$ getJSON .fail没有开火

无法提醒$ getJSON .fail:

this.flickrPics = ko.observableArray(); ko.computed(function() { $.getJSON( 'https://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?', { tags : data.name, format : 'json' }) .done(function(response) { for (var i = 0; i < 10; i++) { self.flickrPics.push(response.items[i].media.m); } }) .fail(function(error) { alert(error + 'error'); // $('.pics-box h2').text("sorry, pictures cant be loaded at the moment"); }); }, this); 

除了.fail之外,一切都很完美。 如果我弄乱了url,没有任何反应,只能获得失败的ajax调用的控制台错误。 我究竟做错了什么?

为了保持与旧浏览器的兼容性,jQuery 1.11.x使用.onreadystatechange来跟踪jsonp请求何时返回。 因此,在发送脚本或jsonp请求时,无法跟踪超时错误以外的错误。

为了解决这个问题,您应该在现代浏览器中使用jQuery 2.x,并且在旧版浏览器中仅包含1.11.x,这样您的大多数用户都可以获得更好的error handling。 为其他用户修复它的唯一方法是不使用jQuery发送此请求,而是自己创建脚本标记,并找到一种跟踪成功/错误的方法,该方法适用于所有支持的浏览器。 或者您可以使用您的服务器代理此请求并执行正常的XMLHTTP请求。

https://github.com/jquery/jquery/blob/1.11.3/src/ajax/script.js#L57

https://github.com/jquery/jquery/blob/2.1.3/src/ajax/script.js#L44