0

我尝试使用 express 和backbone.js 对寄存器进行编程。快递部分看起来像这样

    app.post('/signup', function (req, res) {

    var name = req.param("name", null);
    var country = req.param("country", null);
    var email = req.param("email", null);
    var cemail = req.param("cemail", null);
    var password = req.param("password", null);

    if (email !== cemail ||
    !validate.Email(email) ||
    email == null) {
        console.log("There is something wrong with email address");
        res.send(400, "Please check your email address.");
        return;
    };

    if (password == null || !validate.Password(password)) {
        console.log("There is something wrong with password");
        res.send(400, "Password doesn't match security requirements");
        return;
    };

    if (name == null || country == null) {
        console.log("Some fields is not filled with value.");
        res.send(400);
        return;
    };

    signup(name, country, email, password);
    res.send(200);

});  

如果用户提供了无效的电子邮件地址,那么它将以 http 代码 400 和一些文本进行响应。现在我的问题是,我怎样才能在backbone.js 站点上赶上这段文字。有没有可能。前端backbone.js代码

   $.post('/signup', {
        name: $('input[name=name]').val(),
        country: $('input[name=country]').val(),
        email: $('input[name=email]').val(),
        cemail: $('input[name=cemail]').val(),
        password: $('input[name=password]').val()
    }, function(data) {
        console.log(data);
    }).error(function(){
        console.log("Sign up error");
    });
    return false; 
4

1 回答 1

2

$.post error回调将传递对象,该对象response将包含文本错误消息。

.error(function(response){
    console.log("Sign up error", response.responseText);
});
于 2013-05-21T18:40:00.917 回答