我正在关注本教程并尝试将其应用到我的简单登录用例中。
简单的 jQuery ajax 调用是:
$.ajax({
type: "POST",
url: "/api/element/User.php",
data: {
req: "REQUSERSIGNIN",
platform: "WEB",
useremail: $('form#userSignIn #userEmail').val(),
userpass: $('form#userSignIn #userPassword').val()
},
dataType: "json",
success: function(data) {
console.log("you've been logged in!"
}
});
当然这是调用:
$('form#userSignIn').submit();
我使用主干的尝试是:
var events = _.clone(Backbone.Events);
var SigninModel = Backbone.Model.extend({
url: '/api/element/User.php'
});
var SignInCollection = Backbone.Collection.extend({
model: SignInModel
});
var SigninView = Backbone.View.extend({
events: {
'submit form#userSignIn': 'signIn'
},
initialize: function() {
console.log('Sign in view initialized');
},
signIn: function(e) {
e.preventDefault();
// How do I pass in the data as above?
}
});
$(document).ready(function(){
// What do I instantiate to make it all work?
});
我如何传递数据?