Can any body explain me this ajax code?

var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
document.getElementById(“demo”).innerHTML = myObj.name;
}
};
xmlhttp.open(“GET”, “json_demo.txt”, true);
xmlhttp.send();

just now i started learning the ajax

Hope this helps…

// create the xmlhttp request....
var xmlhttp = new XMLHttpRequest();
// define what to do with the response....
xmlhttp.onreadystatechange = function() {
    // readystate means the request has completely sent, 200 means the response came back successfully
    if (this.readyState == 4 && this.status == 200) {
       // get the response text from the JSON object....
       myObj = JSON.parse(this.responseText);
       // assign the name to the element with ID="demo"
       document.getElementById("demo").innerHTML = myObj.name;
    }
};
// open the connection and send the request....
xmlhttp.open("GET", "json_demo.txt", true);
xmlhttp.send();
2 Likes

Thanks for the help

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.