我有一个非常简单的ajax调用,它将达到成功状态但不会达到错误状态它只会抛出404.奇怪的是这在IE中运行得很好但在firefox或chrome中没有。如果我将数据类型更改为文本,它在Firefox中可以正常工作,但不适用于IE。任何帮助表示赞赏!
$.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");
});
答案 0 :(得分:0)
成功和错误不存在。您需要调用JS函数完成,然后失败。另外,为了获得最佳实践,请在失败情况下使用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");
});