Chinaunix首页 | 论坛 | 博客
  • 博客访问: 404631
  • 博文数量: 112
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 905
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-05 21:14
文章分类

全部博文(112)

文章存档

2009年(3)

2008年(24)

2007年(55)

2006年(30)

我的朋友

分类:

2007-12-06 16:22:57

方法不错!
 
var xmlhttp = false,isComplete = false;//创建XMLHttpRequest对象
 
function createXMLHttpRequest() {
  if(window.XMLHttpRequest) { //Mozilla 浏览器
   xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) { // IE浏览器
   try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {}
   }
  }
}
function Ajax(){
createXMLHttpRequest();
if (!xmlhttp && typeof XMLHttpRequest != 'undefined'){
 xmlhttp = new XMLHttpRequest()
}
this.open = function(url, method, feedback,process, arg,asyc){
    if (!xmlhttp) return false;
    isComplete = false;
 var asy;
 if(asyc==null){asy=true;}else{asy=false;}
 if(arguments.length==2){feedback=method;method="post";}
 method = method.toUpperCase();
 
 try{
  xmlhttp.setRequestHeader("Cache-Control: no-store, no-cache, must-revalidate");
  xmlhttp.setRequestHeader("Connection","close");
 }catch(e){}
    try{
      if (method == "GET"){
        xmlhttp.open(method, url+"?"+arg,asy);
        arg = "";
      }else{
        xmlhttp.open(method, url, asy);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      }
   xmlhttp.send(arg);
  
   getValue_timer=setTimeout("this.Abort()",60000);
      xmlhttp.onreadystatechange = function(){
          if (xmlhttp.readyState == 4 && !isComplete){
          isComplete = true;
    clearTimeout(getValue_timer);
        if(xmlhttp.status==200||xmlhttp.status==0){
      try{var json=eval(xmlhttp.responseText);}catch(e){var json="not support";}
      try{feedback(xmlhttp.responseText,xmlhttp.responseXML,json);}catch(e){}
     }else{
      try{feedback(xmlhttp.status);}catch(e){}
     }
           }else{
     try{process(xmlhttp.readyState);}catch(e){}
     }
    };
     
    }
    catch(z) { return false; }
    return true;
  };
  this.Abort=function(){alert('获取数据失败');try{this.abort();}catch(e){}};
  return this;
};
//post ("/login.do",signOnOff,"action=Bsign&object=Member")
function post(url,done,arg){
var ajax=new Ajax();
var load=function(){};
ajax.open(url,"POST",done,load,arg);
}
function get(url,done,arg){
var ajax=new Ajax();
var load=function(){};
ajax.open(url,"GET",done,load,arg);
}
//form表单中的数连接
 function convertFormObjs2Arrays(formObj){
   for(var x = 0; x < formObj.length; x++){
    var item =formObj[x];
    paramArray+=item.name+ '=' +item.value+ '&';
     }
  return paramArray;
}
阅读(1180) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~