Hey Dave,
Yes, I'm using ASP.NET web method inside an ASPX page.
I tried your solution, but didn't work.
Here, the code that I used.

Default.js
  function Call() {

    var person = { "fname" : "John",
                   "lname"  : "Doe"};

    $.ajax({
      type: "POST",
      url: "Default.aspx/WebMethod",
      //data: {},
      data: person,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        alert('Successful');
      }
    });
  };

Default.aspx.cs
        [WebMethod]
        public static object WebMethod(string fname, string lname)
        {
            return new { fname = fname, lname = lname };
        }

Didn't work..
Apart from that, isn't there a way to recognize the JSON object as
Object and type-cast it to a similar .NET object?
I found something here,
http://www.dennydotnet.com/post/2008/03/03/Passing-a-JSON-object-to-a-WCF-service-with-jQuery.aspx
But it is using WCF which I don't want to.

Regards,
Mahesh.

On Feb 26, 11:00 pm, David Meiser <dmei...@gmail.com> wrote:
> Are you talking about an ASP.NET web method?
>
> If you are, I think that you'll find it pretty easy using this:
>
>             $.ajax({
>                 type: "POST",
>                 contentType: "application/json; charset=utf-8",
>                 url: "myWebService.asmx/myWebMethod",
>                 data: myJSONObject
>                 dataType: "json",
>                 success: function(json) { // do Stuff }
>             });
>
> Just make sure that myWebMethod takes each item in the JSON object as a
> parameter and everything should work pretty well.
>
> Good luck!
> - Dave
>
> On Thu, Feb 26, 2009 at 9:45 AM, Mahesh <mrded...@gmail.com> wrote:
>
> > Hello,
> > How do I pass a JSON object to a server side web method as a
> > parameter?
>
> > For example:
> > I have the following JSON object.
> > var person = { "firstName" : "John",
> >                    "lastName"  : "Doe",
> >                    "age"       : 23 };
>
> > and I want to pass this object in the data: "{}" block.
> > Is it possible?
>
> > Regards,
> > Mahesh.

Reply via email to