I return a list of values on JSON from database via ajax :
[{"Month":"02-2017","total":"10","total_2":"36"},{"Month":"01-2017","total":"74","total_2":"51"},{"Month":"12-2016","total":"26","total_2":"47"},{"Month":"11-2016","total":"307800","total_2":"111"}]
And I expected to after using parse.JSON(obj), I could push the items to a javascript variable and select if necessary:
var values = [];
$.ajax({
url:'data.php?values=yes',
dataType: 'json',
success:function(data){
$.each(data, function(key, item) {
//console.log(item);
values.push(item);
});
}
});
Select like "values[index].Month" or something like that.
What would be a good way to do this?
Answer: This way worked pretty well:
function handleData( responseData ) {
// Do what you want with the data
console.log(responseData);
}
$.ajax({
url: "hi.php",
...
success: function ( data, status, XHR ) {
handleData(data);
}
});