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

  • 相关阅读:
    高级选择器
    CSS的选择器
    HTML——标签
    HTML
    并发编程——协程
    并发编程——线程(二)
    并发编程——线程
    4.栈
    3.链表
    2.顺序表
  • 原文地址:https://www.cnblogs.com/otways/p/9913509.html
Copyright © 2020-2023  润新知