• ajax 基础


    属性 描述
    onreadystatechange 每个状态变化都会触发这个事件处理器
    readyState 请求的状态: 0 未初始化 1 正在加载 2 已经加载 3 交互中 4 完成
    responseText 服务器返回的值
    status HTTP响应代码 200 OK 404 Not Found 等

    var xmlHttp;
    function createXMLHttp(){
        if(window.ActiveXObject){//ie
            xmlHttp=new ActivXObject("Microsoft.XMLHTTP");
        }

      else if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest();
        }
    }

    function startRequestByGet() {//GET请求只能是把东西都放到URL中这样最大可以发送2kb的数据
        createXMLHttp();
        xmlHttp.onreadystatechange = handleStateChange;
        xmlHttp.open("GET", "*.ashx?action=...", true);
        xmlHttp.send(null);
    }


    function startRequestByPost(arg)  //POST方法是把要发送的东西放到HTTP HEAD里面

        {  

           CreateXMLHttpRequest();  

           xmlhttp.onreadystatechange = handleStateChange;  

           xmlhttp.open("POST",url,true);  

           xmlhttp.setRequestHeader("Content-Length",arg.lenght);  

           xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");  //用POST的时候一定要有这句 , 冒充浏览器提交一个表单数据

           xmlhttp.send(arg);           

        } 


    function handleStateChange() {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                //要执行的方法

            }
        }  
    }

  • 相关阅读:
    react.js
    shell if,case,for,while语法
    shell判断文件类型和权限
    shell编程之sed语法
    php魔术方法__SET __GET
    git 忽略文件.gitignore
    php设置错误,错误记录
    linux ifconfig显示 command not found
    数据库备份与恢复
    mysql主要技术
  • 原文地址:https://www.cnblogs.com/youbii/p/2560928.html
Copyright © 2020-2023  润新知