ajax基础

var http;
function xuanti(obj){

var url=null;//写action路径
sendRequest(url);
}
//创建XML请求
function createXMLHttpRequest(){
if(window.XMLHttpRequest){
http=new XMLHttpRequest();
}else if(window.ActiveXObect){
try {
           http= new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
           try {
            http = new ActiveXObject("Microsoft.XMLHTTP");
           } catch (e) {}
           }
}
}
//发送请求
function sendRequest(url){
createXMLHttpRequest();
 http.open("post",url,true);
 http.onreadystatechange=process;
 http.send();
 }
  //回调函数,处理action返回的结果
 function process(){
 if(http.readyState==4){
  if(http.status==200){
 var result=http.responseText;
  }else{
  window.alert("请求异常");
  }
  }
}
原文地址:https://www.cnblogs.com/yxwkf/p/5196318.html