如何从jQuery.ajax获取响应状态代码?

在下面的代码中,我要做的就是从jQuery.ajax调用中获取HTTP响应代码。然后,如果代码为301(永久移动),则显示“位置”响应标头:<?xml  version="1.0" encoding="utf-8"?>html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3/TR/xhtml1/DTD/xhtml1-strict.dtd">

jQuery 301 Trial

function 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 () {

}

);

});

Test 301 redirect

Test 404 not found

有人能指出我哪里错了吗?当我检查Firebug中的'jqxhr'对象时,我找不到状态代码,也找不到'Location'响应头。我在'完成'的最后一行设置了断点。

非常感谢。

更多推荐

ajax获取response响应,如何从jQuery.ajax获取响应状态代码?