我无法用我的jquery代码捕获错误的请求错误。
$.get('http://example.com/', {}, function () {}, 'jsonp')
.done(function () {
// never fires
})
.fail(function () {
// never fires
})
.always(function () {
// never fires
});
我刚收到错误
获取http://example.com?callback=jQuery17102424617672804743_1366109250123&_=1366111087274 404(未找到)
答案 0 :(得分:4)
您无法使用.get
来呼叫其他域名。您需要使用.ajax
进行 jsonp 调用。
但是获取错误是不够的。您还需要指定timout
属性。没有它你不会得到错误。
$.ajax({
url: 'http://hq.am/asdasdasdasd?callback=?',
timeout: 3000,
dataType: "json",
error: function(data){
alert('error');
}
});