April 23, 2010

Passing Multiple Values while using jQuery.Ajax()




I recently saw a question on the forums where the user needed to pass the value of multiple textboxes while performing an async HTTP request using $.Ajax()

Here’s how to pass the values of multiple textboxes in the $.Ajax() call. The call is being made to an ASP.NET WebMethod which accepts 3 parameters.

$.ajax({
type: "POST",
url: "Customer.aspx/GetAddress",
data: { v1: $('#tb1').val(),
v2: $('#tb2').val(),
v3: $('#tb3').val()
},
success: function(msg) {
// do something with msg
}
});


'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Passing Multiple Values while using jQuery.Ajax()"
  1. Anonymous said...
    April 28, 2010 9:16 AM

    Try it, no work. Here is Original code:
    data: "{accountnumber: '" + $(this).val() + "'}" --- work
    If I change to:
    data: {accountnumber : $(this).val()} --- no work
    Please help

 

Copyright © 2009-2012 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions