Skip to content

Instantly share code, notes, and snippets.

@ElemarJR
Created November 8, 2012 02:07
Show Gist options
  • Select an option

  • Save ElemarJR/4036107 to your computer and use it in GitHub Desktop.

Select an option

Save ElemarJR/4036107 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Deferred Objects</title>
</head>
<body>
<button id="resolveButton">resolve</button>
<button id="rejectButton">reject</button>
<button id="getStateButton">get state</button>
<div id="output"/>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
var def = $.Deferred()
.done(function() {$("#output").text("success!");})
.fail(function() {$("#output").text("fail!");})
.always(function() {alert('def state changed to ' + def.state());})
$("#resolveButton").click(function() {
def.resolve();
});
$("#rejectButton").click(function() {
def.reject();
});
$("#getStateButton").click(function() {
alert('def object state = ' + def.state());
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment