• 0715JS基础:ajax


    <!DOCTYPE html>
    <html lang="zh">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>Document</title>
    </head>
    <body>
        <div id="nr">
            
        </div>
    </body>
    </html>
    <script type="text/javascript">
        //1、初始化xml http request对象
        if(window.XMLHttpRequest){
            var xml = new XMLHttpRequest();
        }else{
            var xml = new ActiveXObject('Microso.XMLHTTP');
            //针对IE5/IE6浏览器
        }
        var attr = [1,2,3];
        //2、发送请求
        //get方式发送
        //xml.open("GET","chuli.php?fname="+attr,true);
        //传递的变量写到url地址
        //xml.send();
        //post方式发送
        xml.open("POST","chuli.php",true);
        xml.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        xml.send("fname="+attr);
        //3、接受返回值
        xml.onreadystatechange=function(){
            if(xml.readyState==4 && xml.status==200){
                var str=xml.responseText;
                //以字符串形式传回,所以处理页面也要把数据整合成字符串
                console.log(str);
            }
            document.getElementById("nr").innerHTML=str;
        }
    </script>
  • 相关阅读:
    ubuntu18.04 常用命令
    docker常用命令
    git
    y7000 intel nvidia 双显卡安装Ubuntu16.04
    linux中fork() 函数详解
    理解GBN协议
    C++ sort
    最近点对-分治
    方便查看 linux/kernel/system_call.s
    方便查看 linux/kernel/asm.s
  • 原文地址:https://www.cnblogs.com/zhangbaozhong/p/9315264.html
Copyright © 2020-2023  润新知