JohnandSwifty
Technical User
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!';
}
}
}
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!';
}
}
}