zoukankan      html  css  js  c++  java
  • 原生ajax

     1 function fn1(){
     2         //1、创建ajax引擎对象 ---- 所有的操作都是通过引擎对象
     3         var xmlHttp = new XMLHttpRequest();
     4         //2、绑定监听 ---- 监听服务器是否已经返回相应数据
     5         xmlHttp.onreadystatechange = function(){
     6             if(xmlHttp.readyState==4&&xmlHttp.status==200){
     7                 //5、接受相应数据
     8                 var res = xmlHttp.responseText;
     9                 document.getElementById("span1").innerHTML = res;
    10             }
    11         }
    12         //3、绑定地址
    13         xmlHttp.open("GET","/WEB22/ajaxServlet?name=lisi",true); //true表示是异步
    14         //4、发送请求
    15         xmlHttp.send();
    16         
    17     }


    function fn2(){
            //1、创建ajax引擎对象 ---- 所有的操作都是通过引擎对象
            var xmlHttp = new XMLHttpRequest();
            //2、绑定监听 ---- 监听服务器是否已经返回相应数据
            xmlHttp.onreadystatechange = function(){
                if(xmlHttp.readyState==4&&xmlHttp.status==200){
                    //5、接受相应数据
                    var res = xmlHttp.responseText;
                    document.getElementById("span2").innerHTML = res;
                }
            }
            //3、绑定地址
            xmlHttp.open("POST","/WEB22/ajaxServlet",false);
            //4、发送请求
            xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");  //POST发送请求时如果想带参数必须要加的
            xmlHttp.send("name=wangwu");
            
        }
    天下无难事,只要肯攀登!见多识广是多么重要!
  • 相关阅读:
    《财富自由之路》读后感及读书笔记
    echarts3.x 入门
    Ubuntu 16.04 硬盘安装
    语义化版本控制的规范(转载)
    appcan IDE 无法 请求数据
    jQuery extend 函数
    63342 接口 奇遇 IDEA
    C++调用Java的Jar包
    无法打开 源 文件“stdafx.h”的解决方法
    CString的头文件
  • 原文地址:https://www.cnblogs.com/Allen-Wei/p/8994421.html
Copyright © 2011-2022 走看看