I am trying to pass a javascript array to a method in my code behind. The problem is, I need to pass an int to the method along with the array. When I do:
$.ajax({
type: "POST",
url: webMethod,
data: JSON.stringify({ myArray : passedArray }),
it works. But now i can’t seem to figure out how to pass the array to the code behind AND an int.
I need to pass this with the array:
"{'selectID' : '" + $("#ScarTattoos option:selected").val()
since my method paramters are:
public markItem getMarkNoID(int selectID, string[] person)
{
}
You can send a composite JSON object, like this:
Pass this to
JSON.Stringifyin your AJAX call and both desired objects will be sent to the server handler.You’ll have to deserialize it manually though, unless you’re sending it to a web service, which usually does the deserialization itself based on parameter names (when in JSON mode).