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方式需要

  • 相关阅读:
    iphone6闪存检测
    knowledges address
    类linux系统/proc/sysrq-trigger文件功能作用
    iphone 6s pp助手 越狱
    C pointers
    ubuntu15.04 TLS
    ubuntu cenots 禁止本地登陆
    CentOS7
    CentOS7安全设置 yum-cron系统自动更新,firewalld防火墙简单使用
    SAS学习笔记之函数应用
  • 原文地址:https://www.cnblogs.com/otways/p/9913509.html
Copyright © 2011-2022 走看看