The post name should be "Serializing to JSON in jQuery" or something like that but I kind of twisted it the way I faced this issue. If you’re looking for how to do the ajax calling in jQuery and blah da… then you should keep Googling cause this post ain’t come any help on that. This post is basically about how to send an Array object as parameter in jQuery ajax calling.
You must know how to serialize an object to JSON in ASP.NET AJAX, but if we need to send an array from the client I couldn’t find any Microsoft-specific way to do that.
var cities = new Array();
cities = ‘dhk’;
cities = ‘ctg’;
and then we need to turn this into a string to pass to
$.ajax() like this:
Yes there are a number of JSON libraries out there, but you might want to try the jQuery plugin written by Mark Gibson to avoid introducing a new dependency.
It adds the two functions:
$.parseJSON(json_str, [safe]) to parse your object into JSON.
So basically this is what you would do.
- Create your array and serialize it into JSON
- Send it to your web-method.
- Receive it in server side as string with comma delimiter.
- Split the string and put the values into an array.