Here is the JavaScript code that I am currently using:
function generateRequest(){
var request;
if(window.XMLHttpRequest){
// Works with Firefox, Safari, Opera
request = new XMLHttpRequest();
}
else if(window.ActiveXObject){
// Works with IE 5+
request = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
// Error message for old browsers
alert('Your browser does not support this function');
}
return request;
}
// Create the XMLHttpRequest Object
var http = generateRequest();
function sendCustomRequest(method, url, targetDiv){
target = targetDiv;
if(method == "get" || method == "GET"){
http.open(method,url);
http.onreadystatechange = handleServerResponse;
http.send(null);
}
}
var target;
function handleServerResponse(){
if(http.readyState == 4 && http.status == 200){
var content = http.responseText;
if(content){
document.getElementById(target).innerHTML = content;
}
}
}
This specific section of the code:
document.getElementById(target).innerHTML = content;
is responsible for updating the webpage with the response. How can I display a "Loading" message while waiting for the page to fully load?