View Full Version : Ajax & Javacript Array Problem XMLHTTPRequest Multi-Instance Problem ....

01-13-2006, 12:52 AM
1st of all sorry i Posted this In Another Forum By Mistake and I Can't Delete If From There ....

What I'm Asking About Can I Send 2 Requests At The Same Time .. And They Work In Parallel ?? Example If There's 2 Polls In 1 Page .. And Someone Clicked On The 1st One And Click On The 2nd Before The 1st One Is Finished ... is It Possible To Make Array Of Requests ??? The Below Code Doesn't Work .....If I Just Got The Response I Can Handle It Later But Please Tell Me How To Create multi Instance Of The XMLHTTPRequest ...

var req=new Array();
var The_ID=new Array();
// The_ID is An Array Containing The IDs Of Any HTML Part That The Result Of Any Request Will be Executed At E.g Any TD Or something in any table in the HTML ...
function sR(url,params,HttpMethod,anyID){
if (!HttpMethod)
req[req.length]=initXMLHTTPRequest(); // The Problem Is Here ..
for (i=0;i<req.length;i++)
if (req[i]){
req[i].setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
function initXMLHTTPRequest(){
var xRequest=null;
if (window.XMLHttpRequest)
xRequest=new XMLHttpRequest();
else if (window.ActiveXObject)
xRequest=new ActiveXObject("Microsoft.XMLHTTP");
else {
return xRequest;

01-13-2006, 03:58 PM
Because the XMLHttpRequest object is asynchronous (the A in AJAX), you don't need to use more than one. Just check which page the data is coming from in onreadystatechange().

01-13-2006, 05:06 PM
Hmm .. And How Do I Do That ?? I Already Did It Using An Array I Fixed The Above Code the Problem was that I Have To Use req.push instead of req[req.length] cause .push is more suitable to add objects .....

but can u please tell me the other way in more details or mail it to me