jq 抓取html状态码,如何从jQuery.ajax获取响应状态码?

在下面的代码中,我所要做的就是从jQuery.ajax调用中获取HTTP响应代码。然后,如果代码是301(永久移动),显示“位置”响应头:如何从jQuery.ajax获取响应状态码?

/p>

"http://www.w3.org/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'响应头。我在'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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值