Advertisement
Shailrshah

JSON data retrival

Apr 23rd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <div id="json"></div>
  6.  
  7. <script>
  8. var xmlhttp = new XMLHttpRequest();
  9. xmlhttp.onreadystatechange = function() {
  10.     if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
  11.         var arr = JSON.parse(xmlhttp.responseText);
  12.         for(var i = 0; i < arr.length; i++)
  13.            document.getElementById("json").innerHTML +=  '<p>' + arr[i].sub  + ' by '+ arr[i].teacher;
  14.     }
  15. }
  16. xmlhttp.open("GET", "mySubjects.txt", true);
  17. xmlhttp.send();
  18. </script>
  19. <pre>
  20. [{"sub": "Advanced Inernet Technology","teacher": "Prof. Sanober"},
  21. {"sub": "Disrubuted Systems","teacher": "Prof. Bhushan"},
  22. {"sub": "Software Engg","teacher": "Prof. Madhuri"},
  23. {"sub": "Data Mining","teacher": "Prof. Shanti"}]
  24. </pre>
  25. </body>
  26. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement