编程语言
首页 > 编程语言> > 从JavaScript检测HTTP 301状态代码

从JavaScript检测HTTP 301状态代码

作者:互联网

如果请求的文件(带XMLHttpRequest)有301响应,我需要检测客户端.这样做的原因是因为我需要请求与文件相关的其他文件,其中用户已被重定向,并且与请求的第一个文件无关.
有没有办法使用JavaScript或JQuery检测此响应状态代码?

谢谢.

解决方法:

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);
    }
});

标签:jquery,javascript,http-status-code-301
来源: https://codeday.me/bug/20190624/1283203.html