'jQuery.getJSON'无法在Internet Explorer 8中运行

Nat*_*Sri 3 jquery facebook getjson

我正在jQuery.getJSON用来获取Facebook好友列表,但我没有得到它.它在Firefox和Chrome中运行良好,但在Internet Explorer 8中无效.

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

在做了一点研究后,我也尝试了这段代码:

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

Esa*_*ija 8

Internet Explorer 8不支持jQuery正在使用的XMLHttpRequest对象中的CORS .Internet Explorer 8使用XDomainRequest对象,默认情况下jQuery不支持对象.

  • @beardtwizzle,getJSON只是`$ .ajax`和`dataType:"json"`,它不是JSONP,它根本不是ajax类型的请求.JSONP存在于jQuery.ajax中,虽然类型为jsonp,但当字符串包含``callback =?"`时,存在`getJSON`.facebook图形网址在操作系统中,无论如何都不会发送JSONP响应. (3认同)

leo*_*rer 7

试试这个来处理错误:

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

在你的代码中尝试这个hack(根据下面的评论)

jQuery.support.cors = true;
Run Code Online (Sandbox Code Playgroud)