On server I am returning an array after some operations. I want to work with this array after the Ajax call succeeds.
var addPaymentType = function(){
var data = new Object()
data["function"] = "add";
data["payment_type_id"] = $("#payment_types").val();
data["data"] = $("#saveform").serializeArray();
$.ajax({
type: "POST",
url: location.href,
data: data,
dataType: "JSON",
success : function (data)
开发者_JS百科 {
console.debug(data['plan_pt_id']);
}
});
};
But data['plan_pt_id']
is undefined
. If I return not an array, all works pretty. But how can I work with array?
Thank you.
If data is an array, then you access it with e.g.
data[0]
If the first object in your array has a 'plan_pt_id' property, then you can access that with:
data[0].plan_pt_id
or with
data[0]['plan_pt_id']
The next object would be data[1]
, etc.
Lowercase "json" and data['plan_pt_id'],data['descr']
精彩评论