Hi,
I'm trying to get an xml file using an xmlhttprequest with the GET method. My request works fine with any browser except internet explorer.

This one send no http request at all. (using wireshark to monitor).

I thought about a caching issue but it should work at least once.

My code is the following:

var req;
var xmlDoc;

function GetXmlHttpObject()
{
if (window.XMLHttpRequest){
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
}
if (window.ActiveXObject){
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

function initTxCfg()
{

  req=GetXmlHttpObject();
  if (req==null)
    {
    alert ("Your browser does not support XMLHTTP!");
    return;
    }
  var url="TxCfgData.xml";
  req.open("GET",url,false);
  req.send(null);
  xmlDoc=req.responseXML; 
  ...
}
...

Anyone has a clue why ie doesn't send the http request?

Sorry, I should have said the Active X object: ActiveXObject("Microsoft.XMLHTTP")

But my problem remains...

Hi david,
you can try this request instance

var GetXmlHttpObject = ( function() { // Building request object >>>
		var xhr = 0;
			try {
				try { // Handles all major browser, except IE >>>
					if ( "XMLHttpRequest" in window ) {
						xhr = new XMLHttpRequest();
					} else { 
						var PID = [
							"MSXML2.XMLHTTP.6.0",
							"MSXML2.XMLHTTP.5.0",
							"MSXML2.XMLHTTP.4.0",
							"MSXML2.XMLHTTP.3.0",
							"MSXML2.XMLHTTP.2.0",
							"Microsoft.XMLHTTP" ];
						var len = PID.length;
						for ( var x = 0; x < len; ++x ) { // Instance that will invoke IE browser to respond on the client request >>>
							if (( xhr = new ActiveXObject( PID[ x ] ))) {
								break;
							}
						}
					}
				} catch( e1 ) { // for some other browser's that do not understand the two types of calls above
					xhr = window.createRequest();
				}
			} catch( e ) { // invocation failed [EXIT FUNCTION]
				xhr = 0;
			} return xhr;
		} );

and continue the rest of your codes:

Member Avatar for threagnor

HI David

Did you ever get this problem resolved? I'm experiencing exactly the same issue with IE6 failing when it does the req.send()

Regards

Rob

Try this code............

var url = "QuizAjax.asp";
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}


// alert(poststr);
xmlhttp.open("GET",url,true);
xmlhttp.onreadystatechange = getResult;
xmlhttp.send(null);
}

IE6 failing when it does the req.send()

Could we please see your code?

Member Avatar for threagnor

Thanks for you response but I'm afraid your suggestion did not work in IE6.

I'm at the stage where I'm wondering if it isn't something about the URL that IE6 doesn't like - perhaps the length of the URL... More testing, *sigh*.

Member Avatar for threagnor

Hi fxm

Here is the code:
I'm trying to GET or POST a request to a server. The code below works fine in Firefox, Safari, Chrome and IE7+ but fails in IE6 in spite of the xmlHttpCreate function being copied and pasted straight from Microsoft's MSDN site. The place where IE6 fails is on the oReq.send() line. It appears to create an activeX object but just won't send it. I have also tried oReq.send(null) and oReq.send("") but neither works.


function _call(url){

oReq = xmlHttpCreate();
if (oReq != null) {
//oReq.open("GET", url, false);
oReq.open("POST", url, false);
oReq.send(); // <=============== this is where IE6 fails
return oReq.responseText;
}
else {
alert("AJAX (XMLHTTP) not supported.");
}


}

function xmlHttpCreate(){
if (window.XMLHttpRequest) {
return new window.XMLHttpRequest;
}
else {
try {
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch(ex) {
return null;
}
}

}

Any help with this would be greatly appreciated.

oReq.send(); // <=============== this is where IE6 fails

That's what I suspected.
Try oReq.send(''); or oReq.send(null); If neither one works, I will look through my old notes and see whether something else needs to be changed.

Member Avatar for threagnor

I've found the problem! It turns out that URL was too long. The javascript creates an array of parameters then looped through the array and appends them to the url (i.e. things like "name=Rob&gender=male" etc.) using the code below:

for (key in params) {
	tmp_url += "&" + key + "=" + params[key];
}

When I inspected the array I found it was much too long. Instead of just the six parameters I was expecting there were about 28! It turns out that the properties of the array (i.e. things like array.length) were being appended by the above code too. Firefox and IE7+ didn't mind the long url but IE6 choked on it!

I changed the code so that instead of an array it created an object similar to this one below:

var params = {
		per_page: 100,
		user_id: 'Rob',
		gender: 'male',
		id: '123456'
	}

now when it loops through the object I only get what the code puts in there. I'm sure I could have spent time figuring out how to fix the array loop but creating an object instead seemed easier :)

Thanks to everyone who helped.

Cheers

Rob

creates an array of parameters

for (key in params) {
	tmp_url += "&" + key + "=" + params[key];
}

It turns out that the properties of the array (i.e. things like array.length) were being appended by the above code

Really?

If params is an object, that is exactly what should happen [with the additional quirk that older versions of IE generate a key=value pair for every property that the object could possibly have, not just the one(s) to which a value is currently assigned.

If params is an array, you should get a number of elements equal to the current length of the array. And FWIW that is what I see with your code in IE6 here.

Member Avatar for threagnor

The original code put all the parameters into an array. It looked like this:

var params = new Array();
	params['per_page'] = 100;
	params['user_id'] = 'Rob';
	params['gender'] = 'male';
	params['id'] = '123456';

Later, the code loops through the array and appends each member of the array to the url using this code:

for (key in params) {
	tmp_url += "&" + key + "=" + params[key];
}

This code not only appends each member of the array to the url, it also appends each property of the array (i.e. the "built in" properties such as the array's length etc.). When looping through an array it probably would have been better to use a "for" loop something like this:

for (i = 0; i < params.length; i++) {
.........
}

But instead of keeping the array and using a "for" loop I decided it would be more robust to use my own object to hold the parameters.

The original code put all the parameters into an array. It looked like this:

var params = new Array();
	params['per_page'] = 100;
	params['user_id'] = 'Rob';
	params['gender'] = 'male';
	params['id'] = '123456';

Later, the code loops through the array and appends each member of the array to the url using this code:

for (key in params) {
	tmp_url += "&" + key + "=" + params[key];
}

This code not only appends each member of the array to the url, it also appends each property of the array (i.e. the "built in" properties such as the array's length etc.).

Curiouser and curiouser.
I tried this version of your code in standards mode Chrome, Firefox, IE8, and IE6; then in quirks mode Firefox, IE8, and IE6.

Same 4-value string&per_page=100&user_id=Rob&gender=male&id=123456
every time.

Member Avatar for threagnor

I can't explain it either... all I know is that when I examined the url the code was sending it contained all the array properties too. Making the changes I outlined earlier fixed it. I'd love to know why it was behaving this way, but don't have the time right now to spend examining it. Maybe when things calm down on my current project I'll come back to it!

Maybe when things calm down on my current project I'll come back to it!

At some point it will be necessary to see the actual code. Perhaps there is a broken array or an element with the same name as an array or a reserved word used as an identifier or...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.