Skip to content

Instantly share code, notes, and snippets.

@alexanderscott
Created January 2, 2013 06:12
Show Gist options
  • Save alexanderscott/4432615 to your computer and use it in GitHub Desktop.
Save alexanderscott/4432615 to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="lib/jquery-1.6.1.min.js"></script>
<script src="lib/json2.js"></script>
<script src="lib/underscore-min.js"></script>
<script src="lib/backbone-min.js"></script>
<script language="javascript">
$(function(){
var LoginView = Backbone.View.extend({
el: $("#login-form"),
events: {
"click #login": "login"
},
login: function(){
alert("Hello");
}
});
window.LoginView = new LoginView();
});
</script>
</head>
<body>
<form action="/login" id="login-form">
Username: <input type="text" id="username"><br>
Password: <input type="password" id="password"><br>
<button id="login">Login</button>
</form>
</body>
</html>
App.Model.authentication= Backbone.Model.extend({
defaults: {
Username: "",
Password: "",
RememberMe: false,
LoginFailed: false,
LoginAccepted: false
},
url:"api/authentication"
});
$(function(){
var LoginView = Backbone.View.extend({
model: new App.Model.authentication(),
el: $("#login-form"),
events: {
"click #login": "login"
},
login: function(){
this.model.save({username: this.$el.find("#username")},
password: this.$el.find("#password") {
success: function() {
/* update the view now */
},
error: function() {
/* handle the error code here */
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment