如果请求的文件(带XMLHttpRequest)有301响应,我需要检测客户端。这样做的原因是因为我需要请求与文件相关的其他文件,其中用户已被重定向,并且与请求的第一个文件无关。 有没有办法使用JavaScript或JQuery检测这个响应状态代码?
感谢。
答案 0 :(得分:3)
jQuery ajax回调函数提供了大量信息
$.ajax({
url: "test.php",
type: "GET",
data: {},
dataType:"json",
success: function(resp, textStatus, xhr) {
//status of request
console.log(xhr.status);
},
complete: function(xhr, textStatus) {
console.log(xhr.status);
}
});
答案 1 :(得分:1)
您可以将$.ajax
与jquery
这里有你需要的一切:http://api.jquery.com/jQuery.ajax/
如果你看一下“statusCode”的解释,你会发现你可以为每个代码做点什么