Jump to content


Photo

How Do I Get Two Ajax To Load On The Same Page


  • Please log in to reply
1 reply to this topic

#1 sungpeng

sungpeng

    Advanced Member

  • Members
  • PipPipPip
  • 250 posts

Posted 04 December 2012 - 06:58 AM

function Ajax(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("No AJAX!?");
return false;
}
}
}

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('innerscroll3').innerHTML=xmlHttp.responseText;

}
}
xmlHttp.open("GET","http://www.domain.or...hat3.php", true);
xmlHttp.send(null);
}

</script>
<br>
<div id="innerscroll3"></div>




function Ajaxa(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("No AJAX!?");
return false;
}
}
}

xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('innerfetch').innerHTML=xmlHttp.responseText;

}
}
xmlHttp.open("GET","http://www.domain.or...chat4.php",true);
xmlHttp.send(null);
}


</script>
<div id="innerfetch"></div>


I have two ajax scripts on the same page. I got a result that only one is loaded and the other is not. How do i get two ajax to load on the same page ?

Edited by sungpeng, 04 December 2012 - 07:00 AM.


#2 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,238 posts
  • LocationMississauga, Canada

Posted 06 December 2012 - 10:41 AM

Why the name of second function is called - Ajaxa, did you see that?
Just create only one function that will have one parameter to get different values comming from GET.
Just follow the rule of DRY principle ( Don't Repeat Yourself)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com