Jump to content

Ajax Collisions...


Niccaman

Recommended Posts

I'm a bit of a noob with Ajax. I believe i understand most of the ajax process, but i am curious as to whether i am allowed to have more than 1 simultaneous running ajax functions.

 

Say i have an ajax operation running, then another ajax function to another file is called. This seems to cease the previous operation from finishing its processes. Say:

 

var xmlHttp;

function example1()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
	alert ("Browser does not support HTTP Request");
	return;
}
var url="/example.php";
url=url+"?id=1";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getelementbyid('example').innerHTML = xmlHttp.responseText;
	}
};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function example2()
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
	alert ("Browser does not support HTTP Request");
	return;
}
var url="/example2.php";
url=url+"?id=1";
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function stateChanged2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getelementbyid('example2').innerHTML = xmlHttp.responseText;
	}
};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
catch (e)
	{
		//Internet Explorer
		try
  		{
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}
		catch (e)
  		{
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
}
return xmlHttp;
}

 

Is it because im using the same variable "xmlHttp" for both of these functions???

Will they run independent of each other if i make 2 variables?

because i figured they are inside their own functions and arent global....

Link to comment
https://forums.phpfreaks.com/topic/160726-ajax-collisions/
Share on other sites

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.