zoukankan      html  css  js  c++  java
  • ajax创建

    ajax对象创建和使用

    //创建ajax对象
    function createXMLhttp(){
          var xmlhttp;
    	  if(window.XMLHttpRequest)
    	  {// code for IE7+, Firefox, Chrome, Opera, Safari
    	  xmlhttp=new XMLHttpRequest();
    	  }
          else
    	  {// code for IE6, IE5
    	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    	  if(!xmlhttp){
    	   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    	  }
    	  }
        }
    
    
    //发送请求
    function request(){
    xmlhttp.open("GET","test1.txt",true);
    xmlhttp.send();
    xmlhttp.onreadystatechange = callback();
    }
    
    //回调函数
    function callback(){
    //readyState:4代表完成状态。status:200代表成功状态
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
    document.getElementById("myDiv").innerHTML=xmlhttp.responseText; //组织DOM结构
    }
    }
    

      

  • 相关阅读:
    自定义长时间定时器对象
    poj1326
    poj1323
    poj1218
    poj1298
    poj1276
    新年的第一场雪
    Java 语言学习总结
    假使时光能够倒转
    为了回家——春运3日战纪实
  • 原文地址:https://www.cnblogs.com/chenweichu/p/6268095.html
Copyright © 2011-2022 走看看