Skip to content

Instantly share code, notes, and snippets.

@cmarkle27
Created August 5, 2012 01:56
Show Gist options
  • Select an option

  • Save cmarkle27/3261090 to your computer and use it in GitHub Desktop.

Select an option

Save cmarkle27/3261090 to your computer and use it in GitHub Desktop.
Deferred
function getData(){
return $.get('/echo/html/');
}
function showDiv(){
return $.Deferred(function( dfd ){
$('#foo').fadeIn( 1000, dfd.resolve );
}).promise();
}
$.when( getData(), showDiv() )
.then(function( ajaxResult ){
console.log('The animation AND the AJAX request are both done!');
// ‘ajaxResult’ is the server’s response
});​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment