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.

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

Will you give this article a +1 ? Thanks in advance

About The Author

Suprotim Agarwal
Suprotim Agarwal, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) 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 is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook

Follow him on twitter @suprotimagarwal


Anonymous said...

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

Anonymous said...

It will give 500 internal server until and unless you JSON.stringify({accountnumber : $(this).val()})