I receive a Json output from PHP page like this
[{"x":"2018-03-20","y":1,"z":7},{"x":"2018-03-22","y":31,"z":5},{"x":"2018-03-25","y":7,"z":21}]
How can I loop over the results so that I would have access to each of the elements? I have tried something like below but this does not seem to be working.
function LoadResultMorris()
{
$.ajax({
type: "POST",
url: 'admin/data.php',
data: {type1: 'search1'},
success: function(data){
$.each(data.data, function(key, value) {
alert(data[key]);
alert(data[value]);
});
}
});
}
2
Answers
Loop all list of objects in the following format
Given that the data structure you’re working with is a plain array of objects, jQuery isn’t really necessary here. You can use a standard
forEach()
loop, accessing the properties of the object by name. Try this: