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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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