javascript - JSON Parse error: Unexpected identifier -


i pulled directly w3 schools website on json tutorial, keep getting error message json parse error: unexpected identifier "var" , it's pointing line:

"var myarr = json.parse(xmlhttp.responsetext);

<!doctype html> <html> <body> <div id="id01"></div>  <script> var xmlhttp = new xmlhttprequest(); var url = "myserveraddress/mytutorials.txt";  xmlhttp.onreadystatechange = function() {     if (xmlhttp.readystate == 4 && xmlhttp.status == 200) {         var myarr = json.parse(xmlhttp.responsetext);         myfunction(myarr);     } }; xmlhttp.open("get", url, true); xmlhttp.send();  function myfunction(arr) {     var out = "";     var i;     for(i = 0; < arr.length; i++) {         out += '<a href="' + arr[i].url + '">' +          arr[i].display + '</a><br>';     }     document.getelementbyid("id01").innerhtml = out; }  </script> </body> </html> 

edit: requested here link w3 page has tutorial http://www.w3schools.com/json/json_http.asp , here link has demohttp://www.w3schools.com/json/tryit.asp?filename=tryjson_http

also here mytutorials.txt file looks like

var myarray = [ { "display": "javascript tutorial", "url": "http://www.w3schools.com/js/default.asp" }, { "display": "html tutorial", "url": "http://www.w3schools.com/html/default.asp" }, { "display": "css tutorial", "url": "http://www.w3schools.com/css/default.asp" } ] 

also here mytutorials.txt file looks like

that's wrong.

you've put content of box marked myarray in file.

the contents of box marked mytutorials.txt looks this:

[ { "display": "javascript tutorial", "url": "http://www.w3schools.com/js/default.asp" }, { "display": "html tutorial", "url": "http://www.w3schools.com/html/default.asp" }, { "display": "css tutorial", "url": "http://www.w3schools.com/css/default.asp" } ] 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -