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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.