在下面的代码中,我所要做的就是从jQuery.ajax调用中获取HTTP响应代码。然后,如果代码是301(永久移动),显示“位置”响应头:如何从jQuery.ajax获取响应状态码?
/p>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
jQuery 301 Trialfunction get_resp_status(url) {
$.ajax({
url: url,
complete: function (jqxhr, txt_status) {
console.log ("Complete: [ " + txt_status + " ] " + jqxhr);
// if (response code is 301) {
console.log ("Location: " + jqxhr.getResponseHeader("Location"));
// }
}
});
}
$(document).ready(function(){
$('a').mouseenter(
function() {
get_resp_status(this.href);
},
function() {
}
);
});
有人能指出我要去的地方错了吗?当我检查Firebug中的'jqxhr'对象时,我找不到状态码,也没有'Location'响应头。我在'complete'的最后一行设置了断点。
非常感谢。
2011-03-17
Mahesh
+1
https://api.jquery.com/jQuery.ajax/ –
2014-03-17 16:11:34
+0
我知道这是老了,但我想我解决了它(XHR.responseURL):http://stackoverflow.com/a/39416846/4946681 –
2016-09-09 17:28:57