Question
See if you can modify the code of Listings 17.1 and 17.3 to present a message to the user while waiting for an Ajax request
See if you can modify the code of Listings 17.1 and 17.3 to present a message to the user while waiting for an Ajax request to complete.
myAjaxLib.js-17.1
function getXMLHttpRequest()
{
try {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
return new ActiveXObject("Msxml2.XMLHTTP");
}
}
catch(e) {
return new XMLHttpRequest();
}
}
function doAjax(url, query, callback, reqtype, getxml)
{
var myreq = getXMLHttpRequest();
myreq.onreadystatechange = function()
{
while(myreq.readyState !== 4 || myreq.status !== 200){
document.getElementById("message").html("Response loading. Please wait for some time.");
}
//after it comes out of the loop, you can remove the message or display some other message.
document.getElementById("message").html("");
if(myreq.readyState == 4)
{
if(myreq.status == 200)
{
var item = myreq.responseText;
if(getxml == 1) item = myreq.responseXML;
eval(callback + '( item)');
}
}
}
if(reqtype.toUpperCase() == "POST")
{
requestPOST( url, query, myreq);
} else {
requestGET(url, query, myreq);
}
}
function requestGET(url, query, req)
{
var myRandom = parseInt(Math.random()* 99999999);
if(query == '')
{ var callUrl = url + '?rand=' + myRandom;
} else { var callUrl = url + '?' + query + '&rand=' + myRandom;
}
req.open("GET", callUrl, true);
req.send( null);
}
function requestPOST(url, query, req)
{
req.open("POST", url, true);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
req.send(query);
}
metatags.php
0) { echo $ result; } else{ echo "No keywords metatag is available."; } ?>
17.3
http://
Keywords Received:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started