WebMethod vs ScriptMethod

前端 未结 2 1875
陌清茗
陌清茗 2020-12-04 18:01

I have a .NET 3.5 aspx place with a method marked with the [WebMethod] attribute. I\'m calling this with jQuery, sending JSON in both directions. This all works

2条回答
  •  青春惊慌失措
    2020-12-04 18:14

    The ScriptMethodAttribute attribute is optional. (However, methods that can be called from client script must have the System.Web.Services..::.WebMethodAttribute attribute applied.). If a method is not marked with ScriptMethodAttribute, the method will be called by using the HTTP POST command and the response will be serialized as JSON. You cannot override this setting from script.

    from - http://msdn.microsoft.com/en-us/library/system.web.script.services.scriptmethodattribute.aspx

    EDIT: WebMethod and ScriptMethod are not competing attributes. ScriptMethod could be an additional annotation, as the above para says.

提交回复
热议问题