I have a JavaScript function that makes two consecutive Ajax requests using jQuery. I want to make sure that the first request has loaded before the second function is called. Is there a way I can do this?
Either specify async: false
in the $.ajax
options, or make the second ajax call in the complete
callback of the first call.
$.post("script1.php", {data:"val"}, function(response) {
$.post("script2.php", {data:response}, function(results) {
// this second call will be initialized when the first finishes
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With