return false;
}
//ajax应用池
Showbo.Ajax={
pools:[]//存储ajax对象的数组
,getObject:function(){//从数组中获取ajax对象,如果未返回则新建一个ajax对象
for(var i=0;i<this.pools.length;i++)
if(this.pools[i].readyState==0||this.pools[i].readyState==4)return this.pools[i];
this.pools[this.pools.length]=new XMLHttpRequest();
return this.pools[this.pools.length-1];
}
,send:function(cfg){/*cfg示例
{
url:'请求的页面'
,params:'键值对,注意不是json对象'
,method:'post/get,如果为指定则默认为get'
,success:成功时的回调函数
,failure:失败时的回调函数
,otherParams:提供给回调函数的其他参数,可以为json对象
}
成功或者失败的回调函数参数为 (当前的xhr对象,配置文件的中的otherParams)
*/
if(!cfg||!cfg.url)throw("未设置配置文件!");
var method=cfg.method,asy="boolean"==typeof(cfg.asy)?cfg.asy:true;
if(!method||method!="post")method="get";
if(method.toLocaleLowerCase()=='get'){
var _dc=new Date().getTime();//加时间戳防止ie浏览器下的缓存
cfg.params=cfg.params?cfg.params+'&_dc='+_dc:'_dc='+_dc;
if(cfg.url.indexOf("?")!=-1)cfg.url+="&"+cfg.params;
else cfg.url+="?"+cfg.params;cfg.params=null;
}
else if(!cfg.params)cfg.params='';
var o=this.getObject();
if(!o)throw("未能创建ajax对象!");
o.open(method,cfg.url,asy);
if(method.toLocaleLowerCase()=='post')o.setRequestHeader("content-type","application/x-www-form-urlencoded");
o.send(cfg.params);
o.onreadystatechange=function(){
if(o.readyState==4){
if(o.status==200||o.status==0){
if("function"==typeof(cfg.success))cfg.success(o,cfg.otherParams);
}
else if("function"==typeof(cfg.failure))cfg.failure(o,cfg.otherParams);
}
}
}
}









