tags:

views:

57

answers:

1

How do I save items from an aspx page using $.AJAX() ?

Should I use a WebService Method and pass the data to the webMethod and process save.?

like

$.ajax({
   type:"POST",
   url:"Save.aspx/MySaveMethod",
   data:{????}



});

What does data: contain.

Is there a better way. I am using ASP.NET 2.0 and JQuery.

+2  A: 

Normally you'd serialize the form data and send it, though you might only serialize part of it. This would take all of the named input elements from the form and make a query string out of them to pass back with the AJAX request.

$.ajax({
    type:"POST",
    url:"Save.aspx/MySaveMethod",
    data: $('form').serialize(),
    ...
});
tvanfosson
And if you dont have a form, just pass an object literal eg.: {dataOne:"here is some data", dataTwo:"here is another one"}
Cleiton
What are the Params my WebMethod Takes ?>
Greens
Your web method would need named parameters that are either nullable or have the same names as the inputs. Either that or you would need to supply a function that will return a javascript object that has name/value pairs corresponding to the parameters of the web method that are set from whatever inputs you are using.
tvanfosson
Thanks .
Greens