Jump to content

Problem running 2 ajaxrequest function is a row


Liquid Fire

Recommended Posts

when i do:

 

<select name="destination_code" onchange="AJAXRequest('/_assets/ajax/revenue_options.php','get=tour_code&destination_code=' + this.value, 'tour_code_list');">

 

this run the AJAXRequest function just fine but when i do:

 

<select name="destination_code" onchange="AJAXRequest('/_assets/ajax/revenue_options.php','get=tour_code&destination_code=' + this.value, 'tour_code_list'); AJAXRequest('/_assets/ajax/revenue_options.php','get=hotel&destination_code=' + this.value, 'hotel_list');">

 

I am getting this wierd jacascript error:

 

Error: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]"  nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)"  location: "JS frame :: http://netres.studentcity.com/_assets/javascripts/ajax_library.js :: AJAXRequest :: line 32"  data: no]

 

here is the javscript file for my AJAXRequest stuff:

function CreateXMLHttpRequestObject() 
{
var test = null;
if(window.XMLHttpRequest) 
{
	return new XMLHttpRequest();
} 
else if(window.ActiveXObject) 
{
	return new ActiveXObject("Microsoft.XMLHTTP");
}
}

var xml_http_request_object = CreateXMLHttpRequestObject();
var output_id = null;

function AJAXRequest(passed_url, url_variables, passed_output_id)
{
output_id = passed_output_id;
//make sure that the browser supports ajax
if(xml_http_request_object == null)
{
	alert("your browser does not support ajax");
}

var url = passed_url + "?" + url_variables + "&sid=" + Math.random();

//alert(url);

xml_http_request_object.open("POST",url,true);
xml_http_request_object.onreadystatechange = ProcessStateChange;
xml_http_request_object.send(0);
}

function ProcessStateChange()
{
if(xml_http_request_object.readyState == 4 || xml_http_request_object.readyState == "complete")
{
	document.getElementById(output_id).innerHTML = xml_http_request_object.responseText;
}
}

 

and the xml_http_request_object.send(0); line is line 32 where the error is happening, any help would be great.

 

var xml_http_request_object = CreateXMLHttpRequestObject();

when the second call is made, the object above ('xml_http_request_object') is already in use and waiting for onreadystatechange.  The second call cannot use that obj until the first call has finished with it.  The easiest way to fix your problem is to make the first call 'synchronous' as opposed to the usual 'asynchronous'.

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.