var Login = function () { this.Startup = function () { $('#login-button').on('click', this.OnLoginButtonClick.bind(this)); } this.OnLoginButtonClick = function () { $.ajax({ type: "POST", dataType: "json", data: this.GetLoginParmas(), url: "/User/Login", success: function (result) { if (result === false) alert("用户名或密码错误."); else window.location.href = '/Beijing/Index'; }.bind(this) }); } this.GetLoginParmas = function () { return { name: $("#login-name").val(), password: $("#login-password").val() } } }; $(document).ready(function () { var login = new Login(); login.Startup(); });