PageMethods方法的一点研究
PageMethods.FunctionName(Paramter1,Parameter2,...,SuccessMethod, FailedMethod, userContext);
其中,前面Paramter1,Parameter2,...,表示的是FunctionName的参数,类型是Object或Array;
SuccessMethod是需要使用后台返回结果的Js方法,
FailedMethod是当后台的csFunctionName方法发生异常情况下的执行的Js方法(容错处理方法),
userContext是可以传递给SuccessMethod方法,或是FailedMethod方法的任意内容。
大体结构如下:
后台CS方法
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] csFunctionName(string para1,string[] para2,int para3)
{
//...
}
//----------------------------------------------------------------------
前台页面Javascript方法
//成功回调方法
function getFunctionName(rtn)
{
//使用csFunctionName方法返回的 string[]中的值
}
//失败回调方法
function errorFunction(error)
{
//出错处理方法
}
//对外接口方法
function JsFunctionName(para)
{
//debugger;
var str = para;
var arr = new Array('str1','str2','str3');
//PageMethods.FunctionName(str,arr,3, getFunctionName,errorFunction,context);
PageMethods.FunctionName(str,arr,3, getFunctionName,errorFunction);
}
其实这三个方法合起来,就相当于一个前台方法,对外接口方法为:JsFunctionName(para) 。