javascript – jQuery.getJSON().错误()没有在404错误上执行

前端之家收集整理的这篇文章主要介绍了javascript – jQuery.getJSON().错误()没有在404错误上执行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码的简要概述:
$.getJSON(json_url,function(data) {
    // application logic
}).error(function() {
    console.log("error");
});

问题是,当服务器返回404错误时,它似乎没有被处理,因为没有console.log()说错误,但有一个GET请求失败,代码404(未找到)显示在控制台.

我正在使用jQuery 1.9.0.

我正在制作一些简单的错误吗?

解决方法

由于JSONP请求的性质,不会为这些请求调用错误回调.

docs

When data is retrieved from remote servers (which is only possible using the script or jsonp data types),the error callbacks and global events will never be fired.

猜你在找的jQuery相关文章