I have an key value pair array which I need to send to another function through ajax. My array looks something like this
var vitals=new Array();
var vitals["height"]=170;
var vitals["weight"]=55;
the ajax function is
$.ajax({
type: "POST", //GET or POST or PUT or DELETE verb
url: url, // Location of the service
data: JSON.stringify({ccdEntity: vitals }), //Data sent to server
contentType: "application/json; charset=utf-8", // content type sent to server
dataType: "json", //Expected data format from server
processdata: true, //True or False
success: function (msg) {//On Successfull service call
ServiceSucceeded(msg);
}
and the function receiving the value is
public bool GenerateCcd( Array ccdEntity)
when I run the program the function does not display the array with key-values but when I transfer a normal array (i.e) vitals[0]=170, it works fine . Do I need to make an changes for sending the above data to function?
Edit: Tried passing the above array as a JSON object
var vitals= {
"height": "170",
"weight": "55"}
but results still the same
vitalsdeclaration to bevar vitals = {};. That way you can correctly use a key/value pair structure. Using an array, you were setting properties that aren't serialized. An object ({}) is really what you're looking for