Created
May 3, 2012 21:20
-
-
Save mxriverlynn/2589595 to your computer and use it in GitHub Desktop.
AJAX "Command" wrapper
This file contains hidden or 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
// 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