/***
* get 方式传递参数,数据量大会出现问题,数据会截断,传递到服务器端的数据不全,是由于地址栏传参的数据量有限制.
*/
public static function connect(url:String,params:String,callback:Function,type:String="select"):void
{
url = SERVER_ADMIN_URL_ROOT + url + params;
var err:Boolean=false;
var nocache:String=new Date().getTime().toString();
if(url.indexOf("?")==-1)
url = url+"?_nocache="+ nocache;
else
url = url+"&_nocache="+ nocache;
var req:URLRequest=new URLRequest(encodeURI(url));//encodeURI
var loader:URLLoader=new URLLoader(req);
//req.data=paras;
req.method=URLRequestMethod.POST;
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(IOErrorEvent.IO_ERROR, function ff():void{
loader.removeEventListener(IOErrorEvent.IO_ERROR,ff);
if(!err){
Alert.show("网络通讯异常","异常");
err=true;
}
});
loader.addEventListener(Event.COMPLETE,function ok(event:Event):void{
loader.removeEventListener(Event.COMPLETE,ok);
var result:Object=JSON.decode(String(event.target.data));
var evt:QueryEvent = new QueryEvent();
if(type == SELECT){
evt.mutiResultSet = result;
if(result.result is Array){
evt.resultSet = new ArrayCollection(result.result);
}else{
evt.resultSet = new ArrayCollection([result.result]);
}
evt.page.curPage = result.curpage;
evt.page.nextPageIndex = result.nextpage;
evt.page.prePageIndex = result.prepage;
evt.page.totalPages = result.totalpage;
evt.page.totalRecords = result.totalRecords;
}else{
evt.result = result.result;
}
callback(evt);
loader.close();
loader=null;
req=null;
});
loader.load(req);
}
/***
* post 方式传递参数,解决数据量大的传输问题
*/
public static function connectByPost(url:String,params:String,callback:Function,type:String="select"):void
{
var urlRoot:String = SERVER_ADMIN_URL_ROOT + url;
url = SERVER_ADMIN_URL_ROOT + url + params;
var err:Boolean=false;
var nocache:String=new Date().getTime().toString();
if(url.indexOf("?")==-1)
url = url+"?_nocache="+ nocache;
else
url = url+"&_nocache="+ nocache;
var urlVar:URLVariables = new URLVariables(url.substr(url.indexOf("?")+1));
urlVar.obj = params;//encodeURI(params);
Alert_1.show(urlVar.obj+"");
var req:URLRequest=new URLRequest(url);
req.url = urlRoot;
req.method=URLRequestMethod.POST;
req.data = urlVar;
var loader:URLLoader=new URLLoader(req);
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(IOErrorEvent.IO_ERROR, function ff():void{
loader.removeEventListener(IOErrorEvent.IO_ERROR,ff);
if(!err){
Alert.show("网络通讯异常","异常");
err=true;
}
});
loader.addEventListener(Event.COMPLETE,function ok(event:Event):void{
loader.removeEventListener(Event.COMPLETE,ok);
var result:Object=JSON.decode(String(event.target.data));
var evt:QueryEvent = new QueryEvent();
if(type == SELECT){
evt.mutiResultSet = result;
if(result.result is Array){
evt.resultSet = new ArrayCollection(result.result);
}else{
evt.resultSet = new ArrayCollection([result.result]);
}
evt.page.curPage = result.curpage;
evt.page.nextPageIndex = result.nextpage;
evt.page.prePageIndex = result.prepage;
evt.page.totalPages = result.totalpage;
evt.page.totalRecords = result.totalRecords;
}else{
evt.result = result.result;
}
callback(evt);
loader.close();
loader=null;
req=null;
});
if(!Global.debug){
loader.load(req);
}
}