zoukankan      html  css  js  c++  java
  • 原生json的异步操作

     get方式

    //1 获得ajax引擎
                    var xmlhttp = new XMLHttpRequest();
                    //2 设置回调函数
                    xmlhttp.onreadystatechange = function(){
                        if(xmlhttp.readyState == 4){
                            // 只有服务器端响应状态码为200才会执行代码块里面的代码
                            if(xmlhttp.status == 200){
                                alert("响应数据:"“路径” + xmlhttp.responseText);
                            }
                        }
                    };
                    //3 确定请求方式、路径及参数
                    xmlhttp.open("GET","AServlet?username=jack&password=1234");
                    //4 发送请求
                    xmlhttp.send(null);

    post方式:

        //1 获得ajax引擎
                    var xmlhttp = new XMLHttpRequest();
                  //2 设置回调函数
                    xmlhttp.onreadystatechange = function(){
                        if(xmlhttp.readyState == 4){
                            // 只有服务器端响应状态码为200才会执行代码块里面的代码
                            if(xmlhttp.status == 200){
                                alert("响应数据:"“路径”+ xmlhttp.responseText);
                            }
                        }
                    };
                    //3 确定请求方式、路径及参数
                    xmlhttp.open("POST","");
                    //4.处理中文乱码
                    xmlhttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
                    //5 发送请求
                    xmlhttp.send("username=杰克&password=1234");

    两者的区别在于:

    get不需要处理中文乱码,而post方式需要

  • 相关阅读:
    Graphics Card Notes | 烧卡日记(显卡常识笔记)
    PyCharm Notes | PyCharm 使用笔记(远程访问服务器code配置指南)
    Python Notes | Python 备忘笔记
    conda清华镜像(TUNA)使用指南
    vim 操作手册
    WebNotes(PHP、css、JavaScript等)
    Linux网络配置:设置IP地址、网关DNS、主机名
    Linux挂载:VMware tools for Linux安装
    Linux磁盘分区的理解
    什么是Python?Python的设计哲学?如何获取/升级Python?
  • 原文地址:https://www.cnblogs.com/otways/p/9913509.html
Copyright © 2011-2022 走看看