开发者

Page Method Used for $.ajax({}) Having Warnings

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 <a开发者_运维技巧sp: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 var has been used as a function parameter. The erroneous line of code

ReturnSerialized:function(var,succeededCallback, ...

is part of proxy code generated by microsoft ajax.

Good news is that from your subject line, it appears that you are using jquery ajax method to access the page method. In such case, you don't need the proxy js code - so you can turn it off by setting EnablePageMethods="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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜