JavaScript Arrays via JQuery Ajax to an ASMX WebMethod

This is a problem that has haunted me today. So… I have a WebMethod in an ASMX WebService. That method takes 3 parameters: string, integer and a List/IEnumerable/Array of strings. There is also a JavaScript code, that should execute the WebMethod using JQuery AJAX method. And this way the problem has arisen: how to send the JavaScript array as a List/IEnumerable/Array?

To understand and solve the problem it was really good to read following articles:

So now it’s time for a solution…

The WebMethod that should be called:


And the snippet from corresponding JavaScript file:


As you can see, I’ve instantiated the ‘dataToPass’ object that contains all the data that will be passed to WebMethod. Then I’ve created the JSON string by serializing the ‘dataToPass’ object. It was done by using the json2.js plugin. And finally, such text containing JSON content could be passed as a parameter to the JQuery Ajax method.


3 thoughts on “JavaScript Arrays via JQuery Ajax to an ASMX WebMethod

  1. Instead I put a string – mobilePhones[in] = “string” – I desire to put an array inside the array – mobile Phones[iphones{param:a, param:b} ?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s