ksgush Posted January 6, 2008 Share Posted January 6, 2008 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> Quote Link to comment Share on other sites More sharing options...
ksgush Posted January 6, 2008 Author Share Posted January 6, 2008 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.