zoukankan      html  css  js  c++  java
  • 原生ajax请求的五个步骤

    //第一步,创建XMLHttpRequest对象
    var xmlHttp = new XMLHttpRequest();
    function CommentAll() {
    //第二步,注册回调函数
    xmlHttp.onreadystatechange =callback1;
    //{
        //    if (xmlHttp.readyState == 4)
        //        if (xmlHttp.status == 200) {
        //            var responseText = xmlHttp.responseText;
        //        }
        //}
    //第三步,配置请求信息,open(),get
         //get请求下参数加在url后,.ashx?methodName = GetAllComment&str1=str1&str2=str2
          xmlHttp.open("post", "/ashx/myzhuye/Detail.ashx?methodName=GetAllComment", true);
        //post请求下需要配置请求头信息
        //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        //第四步,发送请求,post请求下,要传递的参数放这
        xmlHttp.send("methodName = GetAllComment&str1=str1&str2=str2");//"
    }
    //第五步,创建回调函数
    function callback1() {
        if (xmlHttp.readyState == 4)
            if (xmlHttp.status == 200) {
                //取得返回的数据
                var data = xmlHttp.responseText;
                //json字符串转为json格式
                data = eval(data);
                $.each(data,
                    function(i, v) {
                        alert(v);
                    });       
            }
    }

  • 相关阅读:
    angular2怎么使用第三方的库(jquery等)
    线性代数:方程组的几何解释
    2016新的计划
    ES+Hbase对接方案概述
    sparkR操作HDFS上面的CSV文件
    spark1.6配置sparksql 的元数据存储到postgresql中
    spark读写Sequoiadb
    Spring Boot与Docker部署
    Docker中使用Tomcat并部署war工程
    CentOS7安装使用Docker
  • 原文地址:https://www.cnblogs.com/li-ding-yong/p/13347286.html
Copyright © 2011-2022 走看看