This is code I’m using right now to do AJAX via JQuery:
$.ajax({
type: "POST",
url: linktopage,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$.each(data, function (index, item) {
alert(item.productId);
});
},
error: function (xhr, status, error) {
}
});
where index = d and item = “[{“productId”:5284598},{“productId”:5790923}]” but alert(item.productId) is undefined, how can i access each productId?
In your example, there is an array of items. You must iterate that to get to the productId.
edit
It is possible that your data is still a string, in which case, you may want to use
before iterating. (more on parse: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/parse )
like this (you could also test to see if it were a string first):