Created
January 2, 2013 06:12
-
-
Save alexanderscott/4432615 to your computer and use it in GitHub Desktop.
This file contains 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
<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