Skip to content

Instantly share code, notes, and snippets.

@akkunchoi
Created December 4, 2013 15:16
Show Gist options
  • Select an option

  • Save akkunchoi/7789212 to your computer and use it in GitHub Desktop.

Select an option

Save akkunchoi/7789212 to your computer and use it in GitHub Desktop.
<html><head><meta charset="UTF-8" /></head><body>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<a href="#" class="s">Success</a>
<a href="#" class="f">Fail</a>
<script>
var df = jQuery.Deferred();
df.then(function(){
alert('then');
}).fail(function(res){
console.log(res);
alert('fail');
}).always(function(res){
console.log(res);
alert('always');
});
$('.s').on('click', function(){
df.resolve("s");
});
$('.f').on('click', function(){
df.reject("f");
});
</script>
</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment