Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created May 3, 2012 21:20
Show Gist options
  • Save mxriverlynn/2589595 to your computer and use it in GitHub Desktop.
Save mxriverlynn/2589595 to your computer and use it in GitHub Desktop.
AJAX "Command" wrapper
// register a command
Commands.register("login", {
url: "/login",
type: "POST"
});
// later in the application, get the command
var loginCommand = Commands.get("login");
// then set up event handlers for it
loginCommand.on("success", function(response){
// do stuff after login succeeds
});
loginCommand.on("failure", function(response){
// show an error message saying login failed
});
// then execute the command
loginCommand.execute({
username: "me",
password: "secret"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment