javascript - 我们如何将多个参数传递给 PageMethod 的 onSuccess 方法?

标签 javascript asp.net pagemethods

我从 javascript 方法“caller”调用 PageMethod“SameMethod”,这样我就可以从数据库中获取一些值。在我获得值后,控制在“onSuccess”方法中继续。问题是我需要在“onSuccess”方法中使用来自 javascript 方法“caller”的一些变量值(“importantValue”)。

 
function caller(){
    var importantValue = 1984;   
    PageMethod.SomeMethod(param1,..., onSuccess, onFailure)
}

onSuccess 方法应该是这样的:

function onSuccess(pageMethodReturnValue, importantValue ){

}

是否可能,如果可以,如何将多个参数(除了页面方法的返回值)传递给 PageMethod 的“onSuccess”方法?

感谢帮助

最佳答案

调用 PageMethod 时将您的 importantValue 作为附加参数传递。 (如果您在线搜索更多信息,这通常称为上下文参数)

function caller(){
    var importantValue = 1984;   
    PageMethod.SomeMethod(param1,..., onSuccess, onFailure, importantValue)
}

然后您可以按如下方式访问 onSuccess 回调中的值:

function onSuccess(pageMethodReturnValue, context, methodName){
    // context == 1984
}

更新 以解释@JacksonLopes 的 onSuccess 参数 aspalliance website in an article by Suresh Kumar Goudampally 上有很好的描述

重要的一点(修改为使用我的参数名称)是:

The success call back method has three parameters:

  • pageMethodReturnValue - Returns the output of the page method.
  • context - This is used to handle different logic when single callback is used for multiple page method requests. We can also pass an array of values as the context parameter.
  • methodName - This parameter returns the name of page method called.

关于javascript - 我们如何将多个参数传递给 PageMethod 的 onSuccess 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4398243/

相关文章:

javascript - 从angularjs中的服务访问数据

javascript - 如何解析从 jquery 作为响应文本接收到的 xml 数据

javascript - 谷歌应用程序脚本未呈现我翻译的消息

asp.net - 在 ASP.NET 中全局处理静态 aspx [WebMethods] 中的异常

javascript - 如何将表格 td 文本添加到进度值中

c# - 将图像保存到 HDD 或存储为数据库中的字节数组?

asp.net - 根据条件在aspx页面中隐藏项目模板

c# - MVC session 变量在 Localhost 上工作但不在实时服务器上工作?

javascript - PageMethods 和 UpdatePanel

ASP.Net Ajax - PageMethods 同步调用和检索结果