Advertisement
amoussa11

The Client JavaScript

Feb 19th, 2019
406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 0.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>Get data as JSON from a PHP file on the server.</h2>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. var xmlhttp = new XMLHttpRequest();
  11.  
  12. xmlhttp.onreadystatechange = function() {
  13.   if (this.readyState == 4 && this.status == 200) {
  14.     myObj = JSON.parse(this.responseText);
  15.     document.getElementById("demo").innerHTML = myObj.name;
  16.   }
  17. };
  18. xmlhttp.open("GET", "demo_file.php", true);
  19. xmlhttp.send();
  20. </script>
  21.  
  22. </body>
  23. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement