jQuery AJAX request failing in IE

2019-01-07 13:19发布

The following AJAX call is failing in IE.

$.ajax({
    url:"{{SITE_URL}}/content/twitter.json",
    dataType:"json",
    error:function(xhr, status, errorThrown) {
        alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
    },
    success:function(json) {
               ...Snip...
    }
});

The error function returns

Undefined
parsererror
OK

No request is made to the server so I don't think its a problem with the JSON.

Fixed, See #1351389

8条回答
相关推荐>>
2楼-- · 2019-01-07 13:32

For the caching problem why don't you simple use the cache: false parameter?

$.ajax({ 
    url: "yoururl",
    cache: false,
    ....
查看更多
男人必须洒脱
3楼-- · 2019-01-07 13:40

What is the {{SITE_URL}} chunk giving is about. Try looking at the code in view source code of the browser. If the {{SITE _URL}} chunk has a trailing slash and that would make the request url:

http://modomain.com//content/twitter.json

Which could creep IE out?

查看更多
Deceive 欺骗
4楼-- · 2019-01-07 13:46

One major problem with statically generated JSON and IE are the leading "commas", for examples this throws an error in IE:

{
    "one":"hello",
    "two":"hi",
 }

Note the last comma.

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-07 13:46

IE: JSON not defined error resolved at

http://funkatron.com/site/comments/safely-parsing-json-in-javascript/

by using dataType: "json" and avoid parsing

查看更多
孤傲高冷的网名
6楼-- · 2019-01-07 13:47

In newer versions of internet explorer (IE7) it is necessary to write the next line before calling $.ajax, otherwise it would never call the function:

$.ajaxSetup({ cache: false }); //this line before $.ajax!!!
$.ajax({
    //codes
    //codes
    //codes
});
查看更多
聊天终结者
7楼-- · 2019-01-07 13:51

IE caches AJAX requests really aggressively (more so than Firefox, anyway). You need to set the Cache-Control headers in the response appropriately if this is not right for your site.

查看更多
登录 后发表回答