squiblo Posted April 14, 2010 Share Posted April 14, 2010 when i only have this on the page...it works perfectly <script> var xmlhttp; function chat1() { showUser1(); } function showUser1(str) { xmlhttp=GetXmlHttpObject1(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url1="http://localhost/includes/chat/chat_output/sql_output/sql1.php"; url1=url1+"?q="+str; url1=url1+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged1; xmlhttp.open("GET",url1,true); xmlhttp.send(null); } function stateChanged1() { if (xmlhttp.readyState==4) { document.getElementById("chatoneoutput").innerHTML=xmlhttp.responseText; showUser1(); } } function GetXmlHttpObject1() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </script> <div id="chatoneoutput"><b></b></div> the only problem is that i also want this on the page <script> var xmlhttp; function chat2() { showUser2(); } function showUser2(str) { xmlhttp=GetXmlHttpObject2(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url2="http://localhost/includes/chat/chat_output/sql_output/sql2.php"; url2=url2+"?q="+str; url2=url2+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged2; xmlhttp.open("GET",url2,true); xmlhttp.send(null); } function stateChanged2() { if (xmlhttp.readyState==4) { document.getElementById("chattwooutput").innerHTML=xmlhttp.responseText; showUser2(); } } function GetXmlHttpObject2() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </script> <div id="chattwooutput"><b></b></div> You will notice they are nearly the same but different. When I add the second one, the 1st one stops working (nothing is shown) but then the 2nd one works perfectly, how can i make them both work properly without them effecting one another.. thanks Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 Hmm... I don't know. Maybe you shouldn't overwrite xmlhttp? Quote Link to comment Share on other sites More sharing options...
squiblo Posted April 14, 2010 Author Share Posted April 14, 2010 How would I do that, javascript isn't one on my strong points :-\ thanks for the reply Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 14, 2010 Share Posted April 14, 2010 It's not hard. You changed the variable name for all variables except xmlhttp. :-\ Quote Link to comment Share on other sites More sharing options...
squiblo Posted April 14, 2010 Author Share Posted April 14, 2010 that has worked perfectly thanks 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.