jQuery-ajax请求未命中。错误状态
我有一个非常简单的ajax调用,它将进入成功状态,但不会进入错误状态,它只是抛出一个404。奇怪的是,这在IE中很好用,但在firefox或chrome中却不行。如果我将数据类型更改为text,它在firefox中可以正常工作,但在IE中不行。感谢您的帮助jQuery-ajax请求未命中。错误状态,jquery,ajax,Jquery,Ajax,我有一个非常简单的ajax调用,它将进入成功状态,但不会进入错误状态,它只是抛出一个404。奇怪的是,这在IE中很好用,但在firefox或chrome中却不行。如果我将数据类型更改为text,它在firefox中可以正常工作,但在IE中不行。感谢您的帮助 $.ajax({ type: "GET", crossDomain: true, url: 'http://www.google.com', contentType: 'application/j
$.ajax({
type: "GET",
crossDomain: true,
url: 'http://www.google.com',
contentType: 'application/json; charset=utf-8',
dataType: 'jsonp',
jsonp: 'callback'
}).success(function(){
console.log("success");
}).error(function(xhr, ajaxOptions, thrownError) {
console.log("error");
});
成功和错误都不存在。您需要调用JS函数done,而不是fail。此外,为了获得最佳实践,请在失败情况下使用console.error而不是console.log 请尝试以下代码:
$.ajax({
type: "GET",
crossDomain: true,
url: 'http://www.google.com',
contentType: 'application/json; charset=utf-8',
dataType: 'jsonp',
jsonp: 'callback'
}).done(function(){
console.log("success");
}).fail(function(xhr, ajaxOptions, thrownError) {
console.error("error");
});
尝试使用“fail”函数而不是“error”
success
和error
是jquery ajax选项属性。您正在查找完成
和失败
;