Jump to content

xml request not working in for loop


shane07

Recommended Posts

When I run following through 4 different 'select' onchange event. It works well.

But when I tried to run through a for loop only the last array element is processed.

Is my concept with 'readystate' wrong?

function fillnext(){
nextArray=new Array();
nextArray[0]='element1';
nextArray[1]='element2';
nextArray[2]='element3';
nextArray[3]='element4';
nextIdArray=new Array();
nextIdArray[0]='id1';
nextIdArray[1]='id2';
nextIdArray[2]='id3';
nextIdArray[3]='id4';
for(i=0;i<=3;i++){
fnext=nextArray[i];
fnextId=nextIdArray[i];
fillQuery(fnext,fnextId);
}
}
function fillQuery(next,nextId){
present='something';
url='http://<?=$_SERVER['HTTP_HOST']."/"?>fillnext.php';
present=document.getElementById(present).value;
var pageUrl = url+"?present="+present+"&next="+next

if(window.ActiveXObject)
 {
 xmlRequest = new ActiveXObject("Microsoft.XMLHTTP");
 }
 else
 {
 xmlRequest = new XMLHttpRequest();
 }
xmlRequest.open("GET", pageUrl, true);
    xmlRequest.send(null);
xmlRequest.onreadystatechange=function(){
if(xmlRequest.readyState==4){
	if (xmlRequest.status == 200)
	alert(nextId);
                alert(xmlRequest.responseText);
	}
}
}

The 'alert(nextId)' alerts only the last element. But when I put 'alert(nextId)' at the top it alerts all the array elements

Link to comment
https://forums.phpfreaks.com/topic/139240-xml-request-not-working-in-for-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.