/*********************************************************
 * MyAjax class
 * 
 * Author: Ziming <ziming@staff.sina.com.cn,jorygong@gmail.com>
 * Last modified: 2007-9-26
**********************************************************/
Ajax.Service=Class.create();
Ajax.Service.prototype={
_defaultMethod:'get',
asynchronous:true,
initialize:function(){},
Call:function(RemoteUrl,Para,CallBack,LoadingCallBack,pj)
{
if(pj)EvalResp=true;
else EvalResp=false;
options=
{
method:this._defaultMethod,
asynchronous:this.asynchronous,
parameters:Para
}
if(EvalResp)
{
new Ajax.Request(RemoteUrl,{method:options.method,asynchronous:options.asynchronous,parameters:options.parameters,
onLoading:LoadingCallBack,
onSuccess:(function(Req){this.JSONEval(Req,CallBack)}).bind(this)});
}
else
{
new Ajax.Request(RemoteUrl,{method:options.method,asynchronous:options.asynchronous,parameters:options.parameters,onLoading:LoadingCallBack,onSuccess:(function(Req){CallBack(Req.responseText)}).bind(this)});
}
},
Call2:function(RemoteUrl)
{
if(pj)EvalResp=arguments[4];
else EvalResp=false;
options=
{
method:'get',
asynchronous:this.asynchronous
}
new Ajax.Request(RemoteUrl,{method:options.method,asynchronous:options.asynchronous});
},
JSONEval:function(Req,CallBack)
{
if(Req.responseText=='')
{
CallBack(false);
return;
}
var RespValid=true;
try
{
var res=Req.responseText.parseJSON();
}
catch(e)
{
alert('加载内容失败，请刷新页面重试。');
RespValid=false;
}
if(RespValid)CallBack(res);
}
}
