Pass Parameters by Reference into AJAX JSON callback
Not quite sure how I pass a parameter by ref to a AJAX JSON callback C#.NET, e.g. if I have a web method like this:
[WebMethod]
public static string MyMethod(Int32 x, Int32 y, ref Int32 z)
{
z = x + y;
return "Finished!";
}
How do I set up the call below to get the CHANGED value of z without returning it?
var jsonText = JSON.stringify({ x:1, y:1, z:0});
$.ajax({
type: "POST",
url: "myPage.aspx/MyMethod",
data: jsonText,
contentT开发者_Python百科ype: "application/json; charset=utf-8",
dataType: "json",
success: function () { alert("Success"); },
failure: function () { alert("Failure"); }
});
You cannot get the value of Z without returning it. When posting to a WebMethod , you send a copy of your arguments. Similarly, when the web-method returns data, it returns a copy. Your WebMethod does not use the same memory as whatever entity is posting to it (most likely your web-browser). How would you expect a remote WebMethod to change the value, in memory, in your browser?
精彩评论