从JavaScript检测HTTP 301状态代码 [英] Detect HTTP 301 status code from JavaScript

查看:100
本文介绍了从JavaScript检测HTTP 301状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to detect client side if a requested file (with XMLHttpRequest) had a 301 response. The reason of doing this is because I need to request other files related to the file where user has been redirected and not related to the first one requested. Any way to detect this response status code using JavaScript or JQuery?

谢谢。

推荐答案

jQuery ajax 回调函数提供了大量信息

jQuery ajax callback function gives out a lot of info

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

这篇关于从JavaScript检测HTTP 301状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆