Jump to content

Ajax function sometimes showing xhr[null]?


sayedsohail

Recommended Posts

Hi everyone,

 

My xmlhttp function is sometimes not working properly, i mean with some ie browsers its showing error, xhr[null],.

 

Can someone  please correct my mistakes, please.

 

thanks,

 

Here is my code

 

var xhr = new Array(); // ARRAY OF XML-HTTP REQUESTS
var xi = new Array(0); // ARRAY OF XML-HTTP REQUEST INDEXES
xi[0] = 1; // FIRST INDEX SET TO 1 MAKING IT AVAILABLE
function xhrRequest() {


	// xhrsend IS THE xi POSITION THAT GETS PASSED BACK
	// INITIALIZED TO THE LENGTH OF THE ARRAY(LAST POSITION + 1)
	// IN CASE A FREE RESOURCE ISN'T FOUND IN THE LOOP
	var xhrsend = xi.length; 

	// GO THROUGH AVAILABLE xi VALUES
	for (var i=0; i<xi.length; i++) {
		// IF IT'S 1 (AVAILABLE), ALLOCATE IT FOR USE AND BREAK
		if (xi[i] == 1) {
			xi[i] = 0;
			xhrsend = i;
			break;
		}
	}
	// SET TO 0 SINCE IT'S NOW ALLOCATED FOR USE
	xi[xhrsend] = 0;
	// SET UP THE REQUEST


	if (window.ActiveXObject) 
{
		var activeXObjects = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];

	for(var p=0; p<activeXObjects.length; p++)
	{   

	try{
		xhr[xhrsend] = new ActiveXObject(activeXObjects[p]);    }

	catch(err){}
	}
	} 

else if (window.XMLHttpRequest) 
{
		xhr[xhrsend] = new XMLHttpRequest();

	}
	return (xhrsend);
}

// CALLING/CREATING XMLHTTP REQUEST.

var xhri = xhrRequest();			
	xhr[xhri].open('GET', file + query_string), true);

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.