Never too old to learn.

http协议自学(7)

Posted on By Andy Zhu

测试ajax

首先我们要知道ajax是什么:

Ajax“Asynchronous Javascript And XML”(异步 JavaScriptXML),是指一种创建交互式网页应用的网页开发技术。

以上摘自百度

ajax怎么写?

其实我也不知道怎么写,于是从菜鸟网站上抄了一段:

<html>
    <head>
        <meta charset="utf-8">
        <script>
            function loadXMLDoc(){
                var xmlhttp;
                if(window.XMLHttpRequest){
                    xmlhttp=new XMLHttpRequest();
                }else{
                    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange=function(){
                    if (xmlhttp.readyState==4 && xmlhttp.status==200){
                        document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                    }
                }
                xmlhttp.open("GET","/try/ajax/ajax_info.txt",true);
                xmlhttp.send();
            }
        </script>
    </head>
    <body>
        <div id="myDiv"><h2>使用 AJAX 修改该文本内容</h2></div>
        <button type="button" onclick="loadXMLDoc()">修改内容</button>
    </body>
</html>

请注意关注那些辣鸡IE用户

浏览器!

GET /try/ajax/ajax_info.txt HTTP/1.1
Host: localhost:8000
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML,
like Gecko) Chrome/73.0.3683.86 Safari/537.36
Accept: */*
Referer: http://localhost:8000/
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9


好像和普通的get请求没有什么区别。。。

还有因为浏览器向我要数据的时候我由把test.html扔给了浏览器一份,所以变成了两个button

。。。。。。没关系反正都能按。。。。