It creates the ability to communicate with the server, without refreshing the web-page
Sends and Receives information from various types of files
A button that will call the action
The JavaScript code for AJAX action
function makeRequest() {
var httpRequest = new XMLHttpRequest(); //assign variable to the request
httpRequest.onreadystatechange = function() { //check if the system is idle
if (httpRequest.readyState === XMLHttpRequest.DONE) { //check if the process has ended
if (httpRequest.status === 200){ //check if the response was ok
alert("Success!" + "\r\n" + httpRequest.responseText);
} else {
alert('There was a problem with the request. \r\n
The Page has returned error number: ' + httpRequest.status)
}
}
};
httpRequest.open('GET', './00empty.html');
httpRequest.send();
}
The Next TextArea is filled only with part of the target file httpRequest when pressing the button above
With this code
var temp = document.createElement('div'); //create a div
temp.innerHTML = httpRequest.responseText; //fill the new div with all the target page
document.querySelector('.firstResponse').innerHTML =
temp.querySelector('title').innerHTML //bring only the 'title' element
//any class/id or other element can be brought