JSON Ajax

Next ❯jQuery Ajax

  • Ajax is used to exchange data from the server without reloading the webpage
  • turned_in_notJSON via Ajax

    Below example, both your html and json files are in the same folder

    <!DOCTYPE html>
    <html>
    <head><title>JSON Example via Ajax</title></head>
    <body>
    <p>Hi, My name is <span id="show"></span></p>
    <script>
     var xmlhttp = new XMLHttpRequest();
     xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
       //used to convert incoming JSON String into object
       var myObj = JSON.parse(this.responseText);
       //Now you can show your object as per you need
       document.getElementById("show").innerHTML = myObj.name;
     }
    };
    xmlhttp.open("GET", "jsoncode.json", true);
    xmlhttp.send(); 
    </script>
    </body>
    </html>
    "jsoncode.json" file
    { "name":"Riya","age":23 }
    OUTPUT

    Hi, My name is


  • jQuery Ajax
❮ Prev JSON Python
Next ❯jQuery Ajax
TryOut Examples"Learn to Explore..!"

TryOut Editor

receipt