xhrGet calling error instead of load on IE6 when no error occurs

I am converting some clunky old pages to use dojo 1.1, and ran into a snag when doing cross browser testing. Everything is fine in Firefox, but fails in IE 6. The basic approach here is to invoke a php file on the server in response to user click, and have it return a JSON structure based on what it finds in the database. That JSON structure is then used to build a table in a div by DOM manipulation. Looks good, runs fast – but not in IE.

The interesting problem in IE is that the error function is called instead of the load function. If I examine the HTTP response, it is 200 and the response string is “OK” – as you would expect if no error occurred. But how then did that function get invoked, if there was no error? Why not the proper load function? The JSON looks correct, and seems properly interpreted in Firefox.

Here’s what it looks like:

dojo.xhrGet({
url: 'searchResultsJSON.php?' + paramString,
handleAs: "json",
load: function(response, ioArgs) {
if ( response.matches.length == 0 )
alert("No matching records found.");
else {

// do a bunch of DOM manipulation here
}
}
return response;
},
error: function(response, ioArgs) {
alert('Error when retrieving search results from the server: ' + ioArgs.url);
}
});

The JSON stuff is just raw JSON.

{ “matches”: [array full of stuff ] }

Does IE require something else, like headers, perhaps? I’m at a bit of a loss here in how to make this work in other browsers, so I’d appreciate any guidance as to why this isn’t sufficiently portable.

Comments

More info on problem but no solution

I am having the same problem, but I AM returning text. I tried putting a handleAs in to xhrPost just to be sure as was suggested, but this does not work either.

However, I am using IE7.

What I found out is that the onload handler WAS being fired, but then the error handler was fired, too -- making it look as though the query failed.

I have not been able to find a way around this and it appears to be truly a bug.

Solved

Hi,
I stumbled upon the same problem (using xhrPost), the workaround I've found is to remove handleAs: "json", receiving the data as plain text, and then parse the response using dojo.fromJson(data).

Tested on FF 2 and IE6, works flawlessly. :)

Experiencing the same problem

I'm currently experiencing the same problem when making an xhrGet call to a URL returning an ATOM message using IE 6. The functionality loads nicely when invoked by Firefox, but in IE I get a 'type mismatch' error passed to my error handling function.

I'm interested if the poster of this entry resolved the problems and what was the cause.

Back to top