这是我用来创建人体模型的新实例的控制器:
newh: function(req, res) {
var firstName = req.param('firstName');
var lastName = req.param('lastName');
var contact = req.param('contact');
var email = req.param('email');
var home = 'http://localhost:1337/humans';
Human.create({
firstName: firstName,
lastName: lastName,
contact: contact,
email: email
}).done(function(err, user) {
if(err) {
return console.log('Could not create user. Error: ' + err);
}else{
res.redirect('/humans');
}
});
这是我用来将数据发布到控制器的脚本:
$(document).ready(function() {
var firstName = $('#first').val();
var lastName = $('#last').val();
var contact = $('#contact').val();
var email = $('#email').val();
$('#add').on('click', function() {
$.ajax({
type: 'POST',
url: '/humans/new',
data: {
firstName: firstName,
lastName: lastName,
contact: contact,
email: email
},
success: function() {
console.log('Successfully passed data.');
}
});
});
});
每当我发布信息时,都会执行成功功能。尽管如此,我的控制器似乎并没有使用 res.redirect() 调用,它只是生成人体模型的空实例。
有什么问题?
谢谢!