开发者

Strange problem with JQuery ajax in IE9

I been working with some java script, JQuery to be exact and I am having some problems with my Ajax call in IE9, everything works fine in Firefox4 and I get no error however in IE9 console when I am running the script I am getting following error

SCRIPT5009: 'JSON' is undefined 
FeedbackComment.js, line 49 character 17

The code is very simple and standard

$.ajax({
                type: "POST",
                url: defaults.WebServiceURL,
                data: "{ 'collectedFeedback':" + JSON.stringify(collectedFeedback) + "}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
         开发者_C百科       success: function (result) {

                }
            });

There also webservice behind scenes and class that represents collected feedback. However the problem seems to be not related to them.

I am not sure what is happening, can anyone help me please. Thanks in advance


Just want to add that if you are in IE and it defaults into quirks mode or IE 7 or earlier compatibility mode JSON will not be available.


Any time I ever have issues with IE 7,8 or 9, the first thing I check is the charset and ensure it's forced to utf-8. It's very picky about this.

Another thing to keep an eye is content-type header. Ensure it is correct and matches up with the response your sending back. It also tends to be picky about this.

So, for example, if you're making an ajax request and expecting a json response, you should set your content-type to 'application/json; charset=utf-8;'. If you're making an ajax request and expecting html as your response, your content-type should be set to 'text/html; charset=utf-8;'.

Hope this helps someone, as it has me.


I had this problem. Code was working in some pages, and not others. Thanks to the comment from "Rocket Hazmat" above, I was able to identify that the page just needed:

<!DOCTYPE html>

at the top. Without that, the JSON object does not exist! And IE behaves like something out of ancient history. No wonder Microsoft is dumping this code base for a fresh start on a new browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜