Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple requests 1

Status
Not open for further replies.

JohnandSwifty

Technical User
May 31, 2005
192
GB
Hi,

I need to run 3 ajax functions inside one function (see below) - the problem being i cant work out how to make the functions wait for the one before it to finish (see a sample ajax function below) - any ideas?

function getModulePage(queryString,method) {

var navQueryStr = queryString + "&contentType=pageNav";
getPageNav(navQueryStr,method);

var optQueryStr = queryString + "&contentType=pageOpt";
getPageOpt(optQueryStr,method);

var contQueryStr = queryString + "&contentType=pageCont";
getPageContent(contQueryStr,method);
}

function getPageOpt(queryString,method) {
createXMLHttpRequest();

/* Add checkStr here because we always pass it to the content pages */
var queryString = queryString + checkStr;

/* Add the timestamp to the query string */
var url = "action.cfm?" + queryString + "&timeStamp=" + new Date().getTime();

xmlHttp.onreadystatechange = handlePageOpt;

xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function handlePageOpt() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById('pagOptBody').innerHTML = xmlHttp.responseText;
}
else {
document.getElementById('pagOptBody').innerHTML = 'WOOPS!';
}
}
}
 
If you change the "true" here:

Code:
xmlHttp.open("GET", url, true);

to be false:

Code:
xmlHttp.open('GET', url, [!]false[/!]);

then your AJAX with be SJAXed ;-)

Have a read here:


Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi,

Thanks for that - I ended up allowing multiple requests as they didnt actually rely on the other finishing. I worked with the idea of xmlHttp1, xmlHttp2 etc

Im sure im going to come accross a need for your solution though so youve probably saved me a bit of a hunt in the future, thanks!

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top