Passing jQuery object and WebMethod return value to an OnSuccess function

Posted by iboeno on Stack Overflow See other posts from Stack Overflow or by iboeno
Published on 2010-03-31T16:47:26Z Indexed on 2010/03/31 16:53 UTC
Read the original article Hit count: 505

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about jQuery