Last active
August 29, 2015 14:01
-
-
Save pbojinov/7271241557539b6cd18f to your computer and use it in GitHub Desktop.
array of deferred
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
var doStuff = doAsyncThings(); | |
$.when.apply(null, doStuff).done(function() { | |
console.log('done with async stuff'); | |
}); | |
function doAsyncThings() { | |
var deferreds = []; | |
deferreds.push(function() { | |
jQuery.ajax({ | |
url: '/path/to/file', | |
type: 'GET', | |
complete: function(xhr, textStatus) { | |
//called when complete | |
}, | |
success: function(data, textStatus, xhr) { | |
//called when successful | |
}, | |
error: function(xhr, textStatus, errorThrown) { | |
//called when there is an error | |
} | |
}); | |
}); | |
return deferreds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment