'jQuery.getJSON' not working in Internet E

2020-06-27 02:35发布

问题:

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);
    }
});

回答1:

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;


回答2:

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.



回答3:

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.