The following code:
jQuery.extend({
getAnalytics: function() {
var result = null;
$.ajax({
type: 'POST',
dataType: 'json',
url: '/master/analytics/reports',
success: function(data) {
result = data;
console.log(result);
}
});
console.log(result);
return result;
}
});
var results = $.getAnalytics();
console.log(results);
shows this in the console:
{20181002: 0, 20181003: 0, 20181004: "2", 20181005: "9", 20181006: 0, 20181007: 0, 20181008: "2", 20181009: "3", 20181010: "1"}
null
null
I cannot figure out what I did wrong in my request to have result
and results
both come back with null even though result
inside of success has a json string. I'm not understanding something about variables here.