?? json.js
字號:
?// JScript 文件
// Json對象,用于向服務器發送請求并返回,同時可以直接請求一個文件
X2.Json=Class.create();
X2.Json.prototype={
initialize:function(url,tipBox){
this.using=false;
this.url=url;
this.data=null;
this.tipBox=tipBox;
}
,open:function(oper,para,method){
//實現para參數的重載效果,可以是string或者object
if(typeof(para)=='object')para=$H(para).toQueryString();
if(!oper){
oper='none';
para='';
}
if(!method)method='get';
this.using=true;
var self=this;
var option={
parameters:para,
method:method,
onSuccess:function(transport){
var s=transport.responseText.replace(/[\n\r]/g,'');
try{
self.data=eval('('+s+')');
}catch(e){
self.debug(s);
}
this.using=false;
self.onsuccess();
},
onFailure:function(transport){
self.using=false;
self.onfailure();
self.debug(transport);
}
}
var c=this.url.indexOf('?')>=0 ? '&':'?';
this.request=new Ajax.Request(this.url+c+'s='+Math.random()+'&oper='+oper,option);
}
//傳統用法,得到純粹的返回值
,openForText:function(oper,para,method){
//實現para參數的重載效果,可以是string或者object
if(typeof(para)=='object')para=$H(para).toQueryString();
if(!oper){
oper='none';
para='';
}
if(!method)method='get';
this.using=true;
var self=this;
var option={
parameters:para,
method:method,
onSuccess:function(transport){
self.onsuccess(transport.responseText);
},
onFailure:function(transport){
self.using=false;
self.onfailure();
self.debug(transport);
}
}
var c=this.url.indexOf('?')>=0 ? '&':'?';
this.request=new Ajax.Request(this.url+c+'s='+Math.random()+'&oper='+oper,option);
}
,abort:function(){
this.request.transport.abort();
}
,getData:function(){
return this.data;
}
,loadFile:function(url){
var self=this;
var option={
onSuccess:function(transport){
self.data=transport.responseText;
self.onsuccess();
}
,onFailure:function(transport){
self.using=false;
self.onfailure();
self.debug(transport);
}
}
var c=url.indexOf('?')>=0 ? '&':'?';
var request=new Ajax.Request(url+c+'s='+Math.random(),option);
}
,onsuccess:function(){
var jso=this.data;
if(typeof jso=='string'){
this.onlogicalsuccess({data:jso});
}else if(jso.success)this.onlogicalsuccess(jso);
else this.onlogicalfailure(jso);
}
,onfailure:function(){
try{
this.tipBox.show('數據傳輸失敗,請檢查網絡或者重試。');
}catch(e){}
}
,onlogicalsuccess:function(){}
,onlogicalfailure:function(jso){
try{
this.tipBox.show(jso.error);
}catch(e){};
}
,debug:function(transport){
//新開窗口顯式錯誤信息
//var doc=window.open('');
//doc.document.write(transport.responseText);
}
,debug2:function(transport){
//alert(transport.responseText);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -