八月迷情

导航

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");
   
    }
}

 

posted on 2010-10-31 21:24  竹林雨季  阅读(193)  评论(0编辑  收藏  举报