jquery + IE 7 & 8

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?
ps 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.


If this only happening on IE then it is because of a typo in your response. Please show the json you got from the server. You have an object where the last item has a trialling comma.

Like this

 { "l1" : 1, "l2" : 2, }

See how this ends with , } ? It need to end with just } .

Just to confirm, the json looks like this with no surrounding " ?

 {"d":
    {"__type":"PresentationObjects.UserPO",
     "Username":"admin",
     "FullName":"Admin User",
     "Password":"",
     "Roles":15,
     "UserRolesStrings": ["monitor","reports","schedule"­,"administration"],
     "IsAdministrator":true,
     "IsMonitor":true,
     "IsSchedule":true,
     "IsR­eports":true
    }
 }

I see that it says roles is 15 but you only show 4. Did you edit the results?


OK, this is totaly my bad. I upgraded from jQuery 1.4.4 to jQuery 1.6 and didn't notice that my pages actually had problems on ALL browsers.
the problem was with the validation plugin, as described in this question.
thanks to all who took the time to answer.

链接地址: http://www.djcxy.com/p/46102.html

上一篇: 如何在javascript中访问对象的内容?

下一篇: jquery + IE 7&8