ajax.js
window.AJAX = { callBack : {},index : 1, get : function(url,succCall,errCall,timeout,getid){ //var id = this.index++; var id=getid; //alert(id); this.callBack[id] = [succCall,errCall]; uexXmlHttpMgr.open(id,'get',url,(timeout||0)); this._send(id); }, post : function(url,data,succCall,errCall,timeout,getid){ //var id = this.index++; var id=getid; this.callBack[id] = [succCall,errCall]; uexXmlHttpMgr.open(id,'post',url,(timeout||0)); if(data){ for(var k in data){ uexXmlHttpMgr.setPostData(id,0,k,data[k]); } } this._send(id); }, _send : function(id){ uexXmlHttpMgr.onData = this.onData; uexXmlHttpMgr.send(id); //uexXmlHttpMgr.close(id); }, onData : function(inOpCode,inStatus,inResult){ var that=AJAX,callBack = that.callBack[inOpCode]||[]; if(inStatus==-1){ callBack[1] && callBack[1](); delete that.callBack[inOpCode]; }else if(inStatus==1){ callBack[0] && callBack[0](inResult); delete that.callBack[inOpCode]; } } };
调用ajax
//get方法 AJAX.get(url,function(res){ alert(res) },function(){ alert('返回失败'); }); //post方法
AJAX.post(url,{
'sinaid':'1910738505',
'sinaname':'我在这里',
'data':'{"companyid":"1"}',
'token':token
},function(res){
alert(res);
res= eval('(' + res + ')');;
for( var x in res.data){
for(var j in res.data[x]){
alert(res.data[x][j])
}
}
},function(){
alert('返回失败');
});