Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Last active August 29, 2015 14:08
Show Gist options
  • Save fernandoc1/371f33c23b632771bc6e to your computer and use it in GitHub Desktop.
Save fernandoc1/371f33c23b632771bc6e to your computer and use it in GitHub Desktop.
Multiple get requests with promise in jQuery
<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