- Home /
Upload/store string to html/json script??
The html code below : Website.
<html>
<body>
<p>
String Value: <span id="val"></span>
</p>
<script>
var JSONObject = { "stringVal":"This is a string" };
document.getElementById("val").innerHTML=JSONObject.stringVal
</script>
</body>
</html>
And the unity JavaScript code:
var siteURL = "http://zinfection.x10host.com/index.htm";
function Start (){
var form = new WWWForm();
form.AddField("stringVal", "This string has been changed");
var request = new WWW(siteURL, form);
yield request;
if(request.error){
Debug.Log("Request error: " + request.error);
}else{
Debug.Log("Returned text" + request.text);
Debug.Log("Returned data" + request.data);
}
}
I know this isn't setup correctly, but its the best I could do with the knowledge I have. What i'm trying to do is modify the JSONObject stringVal in the html via unity, and it change on the site. I'm planning to have a player leaderboard or save player info on this site, but i need to get this working right first. If anyone knows how to help/what im doing wrong please let me know, its very greatly appreciated! :)
What I need to do is be able to save to the server and access the string variable in unity. I don't know if i've explained very well.
I see you have asked a few more questions since I answered your post.
I will try to explain a few things.
Websites are locally cached/ run on a client ... in most cases your browser... i.e. chrome/ firefox etc
To get updated information they require sending requests to the server which then posts the information back in what is called a postback. This normally requires a refresh of the page but you can do what is called a partial postback that gets around this. The question really is what is it that you are trying to achieve here?
Do you need to display information in realtime on the screen without a postback? Because personally I am not sure why you wouldnt try to build that into your game UI as it will probably be a lot easier to manage.
If you just want a way to store players scores in a league table then you have a lot more options and there are much nicer ways to do it ... for example you could use entity framework to store them in a SQL database or use a C$$anonymous$$S like umbraco where you could actually store them as document types inside the cms... which would be easier for a human to manage or for you to use on your website.
You could still do what I originally said and store it in xml or JSON and then pull that into the page using xslt or a user control.
I think learning some basic asp.net might benefit you if you are trying to do these things.
If anyone sees any faults in my advice please dont hesitate to correct me.
Your answer
Follow this Question
Related Questions
POST using WWW isn't working 0 Answers
Retreive Jsonfile and Read It 0 Answers
Using html JSON script to store varibles 1 Answer
Run website's scripts. 0 Answers
Edior sends a bad www request while webplayer does not 1 Answer