what 27s the logic of ajax

Solutions on MaxInterview for what 27s the logic of ajax by the best coders in the world

showing results for - "what 27s the logic of ajax"
Montserrat
14 Feb 2016
1function loadDoc() {
2  //step 1. as you clearly understand
3  var xhttp = new XMLHttpRequest();
4  //step 2. Here you are defining the function that should run once the data is 'ready' 
5  xhttp.onreadystatechange = function() {
6    if (this.readyState == 4 && this.status == 200) {
7     document.getElementById("demo").innerHTML = this.responseText;
8    }
9  };
10  //step 3. Define what type of request you are making (param 1) and where you are making that request to (param 2)
11  //you are also setting a boolean if the request should be asynchronous (param 3) . Note: that should always be true
12  xhttp.open("GET", "ajax_info.txt", true);
13  //step 4. Send the request to the server resource you defined in step 3. 
14  xhttp.send();
15}
16