从ajax响应头中获取服务器时间 深入理解ajax

<?php
    $act = isset($_GET['act']) ? $_GET['act'] : "out";
    if ($act == "in") {
        echo 1;die;
    }
?>
<html>
    <head>
    
    </head>
    <body>
        <span onclick="getdate()">tiaozhu</span>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
    <script>
        function getdate() {
            $.ajax({
                url:"?act=in",
                sync:"false",
                success:function(res,textStatus,request){
                    console.log(res)
                    console.log(textStatus)
                    console.log(request)
                    console.log(request.getResponseHeader("Content-Type"));
                    console.log(request.getResponseHeader("Connection"));
                    console.log(request.getResponseHeader("Date"));
                }
            })

            var client = new XMLHttpRequest();
            client.open("GET","?act=in", true);
            client.send();
            client.onreadystatechange = function() {
                if(this.readyState == this.HEADERS_RECEIVED) {
                    console.log(client.getResponseHeader("Content-Type"));
                    console.log(client.getResponseHeader("Connection"));
                    console.log(client.getResponseHeader("Date"));
                }
            }
        }
    </script>
    </body>
    
</html>

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页