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:53

is this a copy/paste? the one thing that gets me all the time is leaving the last ',' in an object constructor. that is, most browsers JS accept:

o = { a:1, b:2, c:3, };

but IE chokes on this because the comma after the last item. change it to:

o = { a:1, b:2, c:3 };

and it works.

查看更多
该账号已被封号
3楼-- · 2019-01-07 13:54

Fixed, I changed the content-type from application/json; charset=utf8 to just plain application/json.
I hate IE :)

Also to avoid IE super-caching try this:

var d = new Date();
$.ajax({
        url:"{{SITE_URL}}/content/twitter.json?_="+d.getTime(), 
...Snip...

That way each request is a new url for IE to get :D

查看更多
登录 后发表回答