tags:

views:

213

answers:

2

This ajax request checks if a TIF file exists in a certain directory and either sets a button to open the file or to display an error message if it isn't there.

        $.ajax(
        {
            cache: false,
            url: directory,
            success: function() { $("#img" + row).click(function() { window.location.href = directory; return false; }) },
            error: function(data) { alert(data.responseText); $("#img" + row).click(function() { $("#ImageDialog").dialog("open"); return false; }) }
        });

Sometimes, but not always, IE8 will return a failure even when the file exists and FF and Chrome return successes. I added the "alert(data.responseText)" trying to debug the problem, but I do not ever get the alert box. IE instead fails throwing a "System error: -1072896748".

What is going on?

A: 

It might have something to do with encoding problems (your content being in another charset than it promises). See http://keelypavan.blogspot.com/2006/07/system-error-1072896658-in-ie.html.

MvanGeest
Is there any way to determine what charset is getting returned?If I do just alert(data) I get [object].I tried setting the contentType to charset=utf-8, and that did not stop it from throwing the system error.
wham12
You could try using Firebug in Firefox. But setting the contentType is no use if what you return is not *actually* UTF-8... the problem could be that the browser interprets it as UTF-8 with or without the contentType set, but the charset is actually something incompatible (though that ought to be very exotic...)
MvanGeest
The contentType getting returned should be "image/tiff"... if I put that it continues to work correctly in Firefox, but IE is failing for some reason.If I change the contentType to charset=utf-8, both IE and Firefox fail. However, in Firefox I get the alert box with the image trying to be displayed as text. In IE I continue to receive the system error failure.
wham12
@mvangeest check your response headers.. e.g. `Content-Encoding:gzipContent-Type:text/javascript; charset=UTF-8`
Talvi Watia
A: 

Alright, I believe I found the cause/solution posted over here: http://stackoverflow.com/questions/782532/ie-not-triggering-jquery-ajax-success

It says that

IE appears to trigger failure if it can't parse the response as xml, even if the request was a success, so if you're requesting an image, for example, it would return a xhr.status of 200 in the error block. I stuck my "success" functionality in the success block for FF and in the error block wrapped in an "if (xhr.status == 200)" conditional.

wham12
is it just me, or does IE need overly excessive error-checking?
Talvi Watia
..bizzare, but true - I found that firebug lite was actually causing IE8 to trigger "error" with status 200, removed firebug lite (script tag in HEAD) and it all works!! crazy
zack