Click here to Skip to main content
15,908,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i work with jquery to call page method then i always decorate my method like

C#
[WebMethod]
   public static string GetItems()
   {

      //here will be my code

   }

so i want to know when i need to decorate my method like
C#
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static string GetItems()
        {

           //here will be my code

        }

please show me the importance of ScriptMethod with sample code when it is mandatory. thanks
Posted
Updated 12-Aug-11 3:24am
v2

1 solution

You can choose what's used (verbwise, GET/POST etc) as well as the response format (JSON/XML etc) with ScriptMethod.

Here's more:
ScriptMethod on MSDN[^]

WebMethod was traditionally used with web services so that clients would be able to call them via script. I have used it to return simple values and XML. JSON is a different beast, a gentler, kinder, lightweight beast that is fun to snuggle with. See here[^] for details.

Cheers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900