I have a few very simple AJAX calls using jQuery.
My c# webmethods are marked as [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
and return a correctly-formatted JSON.
This works great in FF, but goes crazy on IE:
the error handler is invoked, where the response
has status = 200
(!!), the responseText
is the valid JSON I want to get, and the statusText
is "parsererror"
.
I saw somewhere on SO (can't seem to find it again now) that the problem is that IE expects an xml format response, and throws parser exception on anything else.
the suggested solution was, basically, using the error handler as a success handler:
$.ajax(
{
url: "SampleScriptService.asmx/Function",
type: "POST",
data: {},
contentType: "application/json;",
dataType: "json",
success: function (result) {
SuccesFunction(result.d);
},
error: function (e) {
if (e.status != 200) {
alert("this is a real error");
}
SuccesFunction(JSON.parse(e.responseText).d);
}
});
this seems really hacky to me. Does anybody know of any other solution?
p.s. things i've already tried: these, this, all solutions suggested here
UPDATE
not sure whether it's related or not, but IE also gives this strange error-
Expected ';' Line: 101139813 Char: 5 Code: 0 URI: http://localhost/sample/samplePage.htm
needless to say, my htm file contains ~100 lines.
If I make no ajax calls (and therefore- the above error handler isn't called) then this error does not appear.