I am using the Query POST AJAX to get data from database. Problem is the function does not returning any value. Here's my code.
var graph = {
_ds2: [],
display_graph: function(){
graph._data = [];
_data = "class=graph&func=get_all";
$.post(window.location.href, {async: false}, _data, function(data){
var data = $.parseJSON(data);
//console.log(data)
for (var i = data.length - 1; i >= 0; i--) {
_ds1 = [];
_ds1.push(parseInt(data[i]['year']), parseInt(data[i]['income']));
graph._data.push(_ds1);
};
///graph.create_graph(graph._ds2.reverse());
//return graph._data;
});
return graph._data;
}
}
I call the function like this.
$(document).ready(function(){
/* graph 1*/
console.log(graph.display_graph());
});