Jump to content

Only One Ajax Call Works At A Time ??


ksgush

Recommended Posts

I write backend management php apps.  I am trying to impliment some ajax features.

 

I am using the below code to retrieve info from a database when the page loads up automatically, then ever 10,12 seconds thereafter, if there is a certain part in the database shows one image and throws it back into the page, and if another type of info, it throws another image back into the page.

 

The problem is, the code I am using, uses the body's onLoad function, I recently had 3 calls to the server working correctly, i changed a few things, and now only 1 call will work at a time.  If anybody has any suggestions on this code or any ideas to my fix, please let me know.

 

 


<script language="javascript" type="text/javascript">
<!--
if (window.XMLHttpRequest){
var xmlHttp = new XMLHttpRequest()
}
else if (window.ActiveXObject){
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function updateLeadCredit(type,recid){
var url = "ajax.php?type=" + type + "&recid=" + recid + "&ms=" + new Date().getTime();
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange = updateCreditText;
      xmlHttp.send(null);
}

function updateCreditText(){
if(xmlHttp.readyState == 4){
var response = xmlHttp.responseText;
document.getElementById("lead_credit_text").innerHTML = response;
}
}
//-->
</script>
<script language="javascript" type="text/javascript">
<!--
if (window.XMLHttpRequest){
var xmlHttp = new XMLHttpRequest()
}
else if (window.ActiveXObject){
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function queueCall(){
var url2 = "ajax_alert.php?type=queue&auth_memid=<?php echo $auth_memid; ?>&ms=" + new Date().getTime();
      xmlHttp.open("GET", url2, true);
      xmlHttp.onreadystatechange = updateQueueCall;
      xmlHttp.send(null);
}
function updateQueueCall(){
if(xmlHttp.readyState == 4){
var response = xmlHttp.responseText;
document.getElementById("queue").innerHTML = response;
setTimeout("queueCall()",12000);
}
}
//-->
</script>
<script language="javascript" type="text/javascript">
<!--
if (window.XMLHttpRequest){
var xmlHttp = new XMLHttpRequest()
}
else if (window.ActiveXObject){
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}

function wwwCall(){
var url = "ajax_alert.php?type=www&ms=" + new Date().getTime();
      xmlHttp.open("GET", url, true);
      xmlHttp.onreadystatechange = updatewwwCall;
      xmlHttp.send(null);
}
function updatewwwCall(){
if(xmlHttp.readyState == 4){
var response = xmlHttp.responseText;
document.getElementById("wwwincoming").innerHTML = response;
setTimeout("wwwCall()",10000);
}
}
//-->
</script>


<body onLoad="wwwCall();queueCall();<?php if(eregi("lead.php",$_SERVER['PHP_SELF'])==TRUE){echo "updateLeadCredit('','$recid');";} ?>">

<span id="queue"> </span>
<span id="wwwincoming"> </span>

Link to comment
Share on other sites

I fixed the problem.

when defining the variable: xmlHttp

I should have defined it a second name on the second call.

 

<script language="javascript" type="text/javascript">

<!--

 

if (window.XMLHttpRequest){

var xmlHttp2 = new XMLHttpRequest()

}

else if (window.ActiveXObject){

var xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");

}

 

function queueCall(){

var url2 = "ajax_alert.php?type=queue&auth_memid=<?php echo $auth_memid; ?>&ms=" + new Date().getTime();

      xmlHttp2.open("GET", url2, true);

      xmlHttp2.onreadystatechange = updateQueueCall;

      xmlHttp2.send(null);

}

function updateQueueCall(){

if(xmlHttp2.readyState == 4){

var response = xmlHttp2.responseText;

document.getElementById("queue").innerHTML = response;

setTimeout('queueCall()',12000);

}

}

 

if (window.XMLHttpRequest){

var xmlHttp = new XMLHttpRequest()

}

else if (window.ActiveXObject){

var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");

}

 

function wwwCall(){

var url = "ajax_alert.php?type=www&ms=" + new Date().getTime();

      xmlHttp.open("GET", url, true);

      xmlHttp.onreadystatechange = updatewwwCall;

      xmlHttp.send(null);

}

function updatewwwCall(){

if(xmlHttp.readyState == 4){

var response = xmlHttp.responseText;

document.getElementById("wwwincoming").innerHTML = response;

setTimeout('wwwCall()',10000);

}

}

//-->

</script>

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.