AJAX基本应用

if (!window.XMLHttpRequest) {
   window.XMLHttpRequest=function (){
    var http_request;
  try {
   http_request = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
   try {
    http_request = new ActiveXObject("Microsoft.XMLHTTP");
   } catch (e) {}
  }
    return http_request;
   }
}

function loadAjaxPage(url,sParams,sMethod) {
 sMethod=sMethod.toUpperCase();
 var loading_msg='检测中...请稍等!';
 var loader=new XMLHttpRequest;
 if (sMethod=='GET')
 {
  urls=url.split("?");
  if (urls[1]=='' || typeof urls[1]=='undefined')
  {
   url=urls[0]+"?"+sParams;
  }
  else
  {
   url=urls[0]+"?"+urls[1]+"&"+sParams;
  } 
  
  sParams=null;
 }
 if (sMethod=='GET')
 {
     url += "&ajaxtime=" + Math.random();
 }
 else if(sMethod=="POST")
 {
     url += "?ajaxtime=" + Math.random();
 } 
 loader.open(sMethod,url,true);
 if (sMethod=="POST")
 {
  loader.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 }
 loader.onreadystatechange=function(){
//  if (loader.readyState==1)
//  {
//      document.getElementById("btnchk").disabled = 'disabled';
//   oContainer.innerHTML=loading_msg;
//  }
  if (loader.readyState==4)
  {
      // oContainer.innerHTML = "";
   eval(loader.responseText);
   //document.getElementById("btnchk").disabled = '';
  }
 }
 loader.send(sParams);
}

car =
{
    chk : function(aa,bb)
    {
   
        $("divchk").innerHTML = '检测中...请稍等!';
        loadAjaxPage("Default6.aspx","aa="+aa+"&bb="+bb,"POST");
   
    }
}

原文地址:https://www.cnblogs.com/lgf8612/p/1865741.html