Created
April 28, 2015 12:57
-
-
Save MaZderMind/5ef15902e0a3e6b04d47 to your computer and use it in GitHub Desktop.
jQuery - Wait for multiple Ajax-Calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> | |
<script> | |
var reqs = []; | |
console.log('start t=5') | |
reqs.push( | |
$.get('sleep.php?t=5', function() { | |
console.log('end t=5'); | |
}) | |
); | |
console.log('start t=8') | |
reqs.push( | |
$.get('sleep.php?t=8', function() { | |
console.log('end t=8'); | |
}) | |
); | |
console.log('start t=4') | |
reqs.push( | |
$.get('sleep.php?t=4', function() { | |
console.log('end t=4'); | |
}) | |
); | |
$.when.apply($, reqs).then(function(data) { | |
console.log('all end', data); | |
}); | |
</script> | |
</head> | |
<body></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment