Hi. I'm trying to get an ajax application to handle mulitple requests simultaneously, but it obviously is not working. I realized this was happening so I created a function to create a new XMLHttpRequest object for each request that would later be set to null and garbage collected. I think that my problem is that javascript does not accept objects by reference as a parameter to a function, so I am still having objects closed before other requests can read the results. Here are my functions:
Code:
function createHTTPObject() {
if (navigator.appName == "Microsoft Internet Explorer") {
var http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
var http = new XMLHttpRequest();
}
return http;
}
function phpCall() {
return 'includes/ajax.php?SSID=' + readCookie('sessionID') + '&userID=' + readCookie('userID') + '&action=';
}
function get(action, div, objHTTP) {
if (!objHTTP) {
http = createHTTPObject();
http.open('get', phpCall() + action);
http.onreadystatechange = function() { get(action, div, http); };
http.send(null);
} else {
if (objHTTP.readyState == 4) {
var response = objHTTP.responseText;
checkLogin(response);
document.getElementById(div).innerHTML = response;
objHTTP = null;
}
}
}
So, the problem lies when my page is constructed with:
Code:
<body onload="get('homePage', 'content'); get('mainMenu', 'mainMenu');">
Only one call is getting through, usually the second. Sometimes both divs will receive the output of the second call. Am I correct here, and if so - is there a solution to this?