handle an arrray posted with $.ajax (jquery) to a webservice
- by burktelefon
I'm trying to post data to a webservice (asp.net 3.5), like below (two variants, one commented):
var array = [3, 2, 5, 1, 7];
var jsonString = JSON.stringify(array);
//var jsonString = '{ "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] }'
$.ajax({
type: "POST",
url: "WebService2.asmx/AddRoute",
data: jsonString,
contentType: "application/json; charset=utf-8",
dataType: "json",
processData: "false",
error: function(msg) {
alert('error' + msg.toString);
}
});
So I need a matching webmethod to recieve it. Something like this:
[WebMethod]
public string AddRoute(/* xxx */)
{
//handle data
}
Could someone please elaborate on how I can fetch the data, where I've typed "xxx"?
I would have thought "int[] array" would do the trick, but it's not working.
Any help would be greatly appreciated :)