-1

I am new JSON. I have written a code like below to call a method in c#. But its not yet all calling the method. Please show me a solution how to call a method with n without parameters

$.ajax({
       type:"POST",
       url:"~/PageName.aspx/test",
       contentType: "application/json; charset=utf-8",
       dataType: "json",
       success: function (msg) {
           alert("s");
       },error: function(msg){
           alert("error" + msg);
       }

       })

C#

public void test()
{

}
ohlmar
  • 958
  • 8
  • 17

2 Answers2

1

Try the above if the method is behind the aspx page.

[WebMethod]
public static string test()
   {

   }

You can also use pagemethods

kostas ch.
  • 1,960
  • 1
  • 17
  • 30
0

check these two places you will get solution to problem

Best way to call a JSON WebService from a .NET Console

and

http://www.codeproject.com/Articles/233698/Consuming-a-Json-WebService-from-a-Csharp-or-VB-Ap

Community
  • 1
  • 1
Malkit Singh
  • 349
  • 1
  • 8
  • I think that Srujan0228 need to consume the webmethod from a aspx page. The examples you posted saying about consume service with WebRequest. – kostas ch. Feb 13 '14 at 13:36