1.) Specify a callback function
function Chart(file, callback) { var chart = undefined $.getJSON(file, function(data) { chart = { categories: data.keys series: [{ name: 'first', data: data.first }, { name: 'niewykopane', data: data.first }] } callback(chart); }); }
2.) Synchronous request (not recommended!)
You can use $.ajax() and set the async property to false .
Warning: This method is not recommended! It blocks the entire user interface, all other JavaScript and timers, until the request is complete!
source share