0
當我提交表單時。代碼不會進入view.on處理程序。 這是因爲玉文件名與動作名稱不同嗎?或者是因爲我使用app.all。爲什麼路由器被擊中,但view.on沒有擊中。?view.on('post',...)在keystonejs中提交表單時未觸及
mycart.jade
if user
a(class='button',href='/purchase') Purchase
else
form.signup-form(method="post" action="signup").row.col-sm-8.col-md-6
input(type='hidden', name='action', value='signup')
.form-group
label Name
.row
.col-sm-6.col-md-6
input.form-control.input-box(type='text', name='first', placeholder='First Name')
.col-sm-6.col-md-6
input.form-control.input-box(type='text', name='last', placeholder='Last Name')
.form-group
label Email
input.form-control.input-box(type='email', name='email', placeholder='Email')
.form-group
label Password
.row
.col-sm-6.col-md-6
input.form-control.input-box(type='password', name='password', placeholder='Password')
button(type='submit').btn.btn-success Purchase
路由器/ index.js
exports = module.exports = function(app) {
// Views
app.get('/', routes.views.index);
app.get('/mycart', routes.views.mycart);
app.all('/signup', routes.views.signup);
};
路由器/視圖/ signup.js
var keystone = require('keystone');
exports = module.exports = function(req, res) {
var view = new keystone.View(req, res);
console.log("this log appears : "+JSON.stringify(req.body));
view.on('post', { action: 'signup' }, function(next) {
console.log('this long is not appearing');
});
};
控制檯
GET /mycart 200 341.217 ms
this log appears :{"action":"signup","first":"sonal","last":"parekh","email":"[email protected]","password":"sankar"}
POST /signup - - ms
啊,我也忘了這個問題。當我問我沒有意識到。現在我更瞭解這個問題。但任何方式謝謝代表其他觀衆。 – enRaiser