I made a page method in the .cs file of my Default.aspx:
[WebMethod]
public static string ReturnSerialized(object var)
{
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
string serialized = jsSerializer.Serialize(var);
return serialized;
}
The function accepts a serializable object and converts it to json.
On my Default.aspx page, inside <form> I added <asp:ScriptManager ID="scriptManager" EnablePageMethods="true" runat="server" />. Everything works fine, but in Firebug there is an error:
missing formal parameter
[Break On This Error] ReturnSerialized:function(var,succeededCallback, failedCallback, userContext)
I’m just wondering how I could handle this error. I’m developing in VS2010, and the jquery lib I’m using on the Default.aspx is 1.6.2.
BTW, if this is similar to another post, please feel free to let me know. Thanks.
The error is due to the fact that reserved java-script keyword
varhas been used as a function parameter. The erroneous line of codeis part of proxy code generated by microsoft ajax.
Good news is that from your subject line, it appears that you are using jquery
ajaxmethod to access the page method. In such case, you don’t need the proxy js code – so you can turn it off by settingEnablePageMethods="false". That would also result in decrease in page size – that’s the one of reason, I use jquery to access page methods.Regardless, I will also suggest you to change your parameter name so that you/other developer does not get into such subtle issues in future.