'jQuery.getJSON' not working in Internet E

2020-06-27 02:29发布

I am using jQuery.getJSON to fetch the Facebook friends list, but I am not getting it. It works perfectly in Firefox and Chrome, but it is not working in Internet Explorer 8.

jQuery.getJSON("https://graph.facebook.com/me/friends?access_token="+aToken,
    function(data) {
        alert(data);
    }
);

Also after doing a little more research I tried with this code also:

jQuery.ajax({
    url:"https://graph.facebook.com/me/friends?access_token="+aToken,
    type: 'json',
    success: function(json) {
        alert(json);
    }
});

3条回答
贼婆χ
2楼-- · 2020-06-27 02:53

I totally solved this problem using Jason Moon script, here

https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest/blob/master/jQuery.XDomainRequest.js

hope it helps.

查看更多
祖国的老花朵
3楼-- · 2020-06-27 03:07

Internet Explorer 8 doesn't support CORS in the XMLHttpRequest object which jQuery is using. Internet Explorer 8 uses XDomainRequest object which jQuery doesn't support by default.

查看更多
Anthone
4楼-- · 2020-06-27 03:11

Try this to handle the error:

jQuery.getJSON("https://graph.facebook.com/me/friends?access_token=" + aToken, 
    function(data) {
        alert(data);
    }
)
.error(function(jqXHR, textStatus, errorThrown) { alert(errorThrown); });

And try this hack in your code (as per comment below)

jQuery.support.cors = true;
查看更多
登录 后发表回答