Thursday, February 26, 2009

[jQuery] Re: Passing JSON objects to a Web Method

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 <mrdedhia@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.

No comments: