Reputation: 537
I have this code and I'd like to stop the script while $.get() is not finished.
$.get("assets/data/html/navigation.html", function(response) {
$('body').append(response);
});
$('body').append('<div class="modal">...</div>');
In this example the second append is executed before the first one.
Thanx for your help
Upvotes: 0
Views: 50
Reputation: 318
According to jQuery documentation:
var jqxhr = $.get("assets/data/html/navigation.html", function(response) {
$('body').append(response);
})
.done(function() {
$('body').append('<div class="modal">...</div>');
})
Upvotes: 1
Reputation: 382132
No, you don't want to stop the script, you want to go on from inside the callback :
$.get("assets/data/html/navigation.html", function(response) {
$('body').append(response);
doOtherStuff();
});
function doOtherStuff(){
$('body').append('<div class="modal">...</div>');
}
Or, using done
:
$.get("assets/data/html/navigation.html", function(response) {
$('body').append(response);
}).done(function(){
$('body').append('<div class="modal">...</div>');
});
Upvotes: 3