将 jQuery 对象和 WebMethod 返回值传递给 OnSuccess 函数
我正在从此代码调用 WebMethod
:
if($(this).attr("checked")) {
..
MyWebMethod(variable1, variable2, onSuccessFunction);
}
MyWebMethod
返回一个整数,我想设置 $(this).attr("id") 到返回的整数。基本上,我试图做相当于 MVC
以及返回值。例如,如果我这样做:Ajax.ActionLink...AjaxOptions {UpdateTargetID =...}
但是,我不知道如何获取对 < code>$(this)
MyWebMethod(variable1, variable2, onSuccessFunction($(this)));
我可以成功操作 jQuery 对象,但显然它没有 MyWebMethod
的返回值。或者,方法签名为 onSuccessFunction(returnValue)
的第一个代码块具有来自 MyWebMethod
的正确返回值,但没有我正在查找的 jQuery 对象的概念。我这一切都错了吗?
I am calling a WebMethod
from this code:
if($(this).attr("checked")) {
..
MyWebMethod(variable1, variable2, onSuccessFunction);
}
The MyWebMethod
returns an integer, and I want to set $(this).attr("id")
of the jQuery object above to the returned integer. Basically, I'm trying to do the equivalent of an MVC Ajax.ActionLink...AjaxOptions {UpdateTargetID =...}
However, I can't figure out how to get both a reference to $(this)
as well as the returned value. For example, if I do:
MyWebMethod(variable1, variable2, onSuccessFunction($(this)));
I can succesfully manipulate the jQuery object, but obviously it doesn't have the return value from the MyWebMethod
. Alternatively, the first code block with a method signature of onSuccessFunction(returnValue)
has the correct return value from MyWebMethod
, but no concept of the jQuery object I'm looking for. Am I going about this all wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道第一个示例中的 onSuccessFunction 到底需要什么参数,但类似的东西将是您正在寻找的。
** 更新 ** 已修复以避免“this”范围问题。
I don't know exactly what parameters the onSuccessFunction in your first example is expecting, but something like this will be what you're looking for.
** Update ** Fixed to avoid a "this" scoping issue.