简体   繁体   English

$ .ajax无法在IE上触发,没有错误

[英]$.ajax not firing on IE, no errors

I know IE8 has been around for a while, and there are many questions about similar problems. 我知道IE8已经存在一段时间了,关于类似问题还有很多问题。 Solution not found in other questions thought I did add some nice ideas from other questions. 在其他问题中找不到解决方案,以为我确实从其他问题中添加了一些不错的想法。 Like don't use $.getJSON in IE and always use cache: false in IE8 calls. 就像不要在IE中使用$.getJSON并始终使用cache: false在IE8调用中为cache: false

So question is why does this do not work in IE8 ? 所以问题是为什么这在IE8中不起作用 Did a for ... in loop but tried also to just alert inside the callback function and nothing. 做了一个for ... in循环,但也尝试只是在回调函数内部发出警报 ,什么也没有。 Feels like the ajax never gets fired... 像ajax永远不会被解雇的感觉。

jsFiddle: http://jsfiddle.net/cmx0yfy8/show jsFiddle: http : //jsfiddle.net/cmx0yfy8/show

Only code in the page (besides loading jQuery in head): 页面中只有代码(除了在头中加载jQuery):

$.ajax({
        url:"https://rawgit.com/umpirsky/country-list/master/country/cldr/en/country.json",
        cache: false,
        dataType: "json"
    }).done(function (data) {
         for (code in data){
        $('body').append('<div>' + code + '</div>'); 
    }; 
});

What does the XHR console look like? XHR控制台是什么样的?

Try switching json to jsonp. 尝试将json切换为jsonp。

Reference: What are the differences between JSON and JSONP? 参考: JSON和JSONP有什么区别?

$.ajax({
    type: GET,
    url:"https://rawgit.com/umpirsky/country-list/master/country/cldr/en/country.json",
    cache: false,
    dataType: "jsonp",
    success: function(data){
        $.each(data, function(index, value) {
          $('body').append('<div>' + data.code + '</div>');
        });     
    }
});

I bet you are doing a cross-domain AJAX call which IE 8 does not support. 我敢打赌,您正在执行IE 8不支持的跨域AJAX调用。 Your best choice is to do it through an XDomainRequest . 最好的选择是通过XDomainRequest

http://msdn.microsoft.com/en-us/library/ie/dd573303%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/ie/dd573303%28v=vs.85%29.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM