Jump to content

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


sungpeng

Recommended Posts

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.org/chat3.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.org/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 ?

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)

Archived

This topic is now archived and is closed to further replies.

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