【发布时间】:2018-01-18 18:14:15
【问题描述】:
我正在编写一个小代码,试图获取服务器 http 状态的返回
目前我已经制定了以下代码(有效),但我想知道为什么调用会跳过成功并直接出错。
这是我目前拥有的代码:
$(document).ready(function(){
$("#test-button").on("click", function() {
$.ajax({
type: "GET",
dataType: 'jsonp',
url: "<<INSERT THE URL>>",
success: function(response) {
alert(response.status);
},
error: function(response) {
if(response.status == 200) {
// Redirecting
window.location.href = '<<INSERT THE URL>>';
} else {
alert('The organisation you entered is not available');
}
}
});
});
});
基本上我只想知道为什么它会跳过成功,即使得到 200 作为回报。
谢谢
【问题讨论】:
-
你能去掉 dataType: 'jsonp' 并检查一下吗?
-
@AmrElgarhy 谢谢,我没有使用错误/成功,而是使用完整的:)
-
@AlanPallath jsonp 用于跨浏览器;否则响应失败。
标签: javascript ajax