我是Ember和jQuery的初学者。我正在尝试实现一个登录页面,我无法理解在登录失败的情况下我应该从服务器端返回什么。我到目前为止编写的代码是:
App.LoginController = Ember.Controller.extend({
loginFailed: false,
login: function() {
this.setProperties({
loginFailed: false
});
var request = $.post("/Login", this.getProperties("username", "password"));
request.then(this.success.bind(this), this.failure.bind(this));
},
success: function() {
// sign in logic
alert("Successful Login");
},
failure: function() {
this.set("loginFailed", true);
}
});
我有一个登录模板,用户名和密码绑定到模板中的输入。目前,我能够在服务器端获取请求,但我无法理解,如果成功和失败,我应该从服务器端返回什么。
答案 0 :(得分:1)
你只想吐出某种输出。你在服务器上运行什么语言?在PHP我会做这样的事情
while(ob_end_clean()); // make sure my output buffer is clean
// This is your object that will be returned to the client
$json_out = array(
'status' => 0 // status 0 equals failed login, 1 will mean success
'message' => '' // if you would like to display a message and have the server control it
);
if($successful_login){
$json_out['status'] = 1;
}
header('Content-Type: application/json');
echo json_encode($json_out);
exit;