I have an Jquery Ajax call like so:
$('body').on('click', '#btnPopulate', function() {
alert(getTree());
});
function getTree() {
var url = getUrlPath() + "/StoryboardAdmin/BuildStoryboardViewModel";
$.ajax({
type: "POST",
cache: false,
url: url,
success: function (result) {
if (result.success === true) {
var data = result.data;
return data;
} else {
return null;
}
},
error: function (responseText, textStatus, errorThrown) {
alert('Error - ' + errorThrown);
}
});
}
When I click the button, the alert box just says 'undefined', as if there is no data being returned But in the ajax call, the "var data = result.data" has loads of data in it when I breakpoint it. So why is this not being returned to the alert box? The data being returned is an array of objects, with each object further containing an array of objects. But the data is definitely being returned from the controller to "var data".