Lets say I have the following js code
$(function() {
$('#some_id').load('myfile.html', function() {
alert('Call back called');
});
alert('You should alert second');
// more javascript code .........
});
For some reason, alert('Call back called'); is the last thing that gets alerted to me. I thought that js code executes in the order of the file. Is there a way to make alert('Call back called'); go first before all my other functions.
Looking at my simple code snippet one would suggest why not put alert('You should alert second'); in the function call back, unfortunately I am inheriting a code base that is really big and jamming all those function calls in my callback wont be feasible
alert('You should alert second');is called immediately when the js is initialized, where the alert('Call back called') will be called only after the .load is called (look into callbacks)..ajax()instead of.load()and setasync: falselike explained here: stackoverflow.com/questions/133310/…