Last active
August 29, 2015 14:08
-
-
Save fernandoc1/371f33c23b632771bc6e to your computer and use it in GitHub Desktop.
Multiple get requests with promise in jQuery
This file contains hidden or 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
<html> | |
<body> | |
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.0.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() | |
{ | |
var requests = new Array(); | |
for (i = 1; i < 10; i++) | |
{ | |
requests.push($.get('files/'+i+'.txt')); | |
} | |
promise = $.when.apply($, requests); | |
promise.done(function() | |
{ | |
$.each(arguments, function(index, responseData) | |
{ | |
document.getElementById("output").innerHTML += responseData[0]+'\n'; | |
}); | |
}); | |
}); | |
</script> | |
<pre id="output"></pre> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment