How to ensure that "Test Data" text get displayed in the console only after books details are loaded in vm.books, basically want to perform synchronous ajax call.
Below mention code is not working as expected. any suggestion how to achieve this expected functionality.
$(document).ready(function() {
var vm = new obj.Books();
vm.loadBooks();
console.log("Test Data");
});
var obj = obj || {};
obj.Books = function() {
var self = this;
self.books = [];
self.loadBooks = function() {
$.ajax({
url: "somewebapiurl",
dataType: 'jsonp',
async: false
})
.done(function(data) {
$.each(data, function(idx, item) {
self.books.push(item);
});
})
.fail(function(xhr, status, error) {
alert(status);
});
};
};