Unable to send multiple AJAX request in a loop?
Posted
by Harish Kurup
on Stack Overflow
See other posts from Stack Overflow
or by Harish Kurup
Published on 2010-06-02T05:41:24Z
Indexed on
2010/06/02
5:43 UTC
Read the original article
Hit count: 210
I am sending multiple AJAX request through a loop, but some request are successfully send not all.. my code goes here...
for(var i=0; i<dataArray.length; i++)
{
var request=getHttpRequest();
request.open('post','update.php',false);
request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
request.send("data="+dataArray[i]);
if(request.readyState == 4)
{
alert("updated the data="+dataArray[i]);
}
}
function getHttpRequest()
{
var request=false;
if(window.XMLHttpRequest)
{
request=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try
{
request=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
request=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
request=false;
}
}
}
return request;
}
here in the above code, some data are being posted, but some dont, it does not return the readyState = 4. i.e if i have array with dataArray['1','2','3','4']; it updates only 1,2,and 4 and skips 3, or other value in between... is there any solution..please help...
© Stack Overflow or respective owner