求助: express建站,mangodb中添加记录,不会进入save回调.
最近在学express建站,写了一个电影网站的demo,遇到一点问题,百思不得其解,求大神指点.
问题描述:
在新增记录的时候,表单填写完成点击导入,请求发送出去了,但是它会一直请求,不会进入save回调,也没有报错.(这里进的是if中else部分的代码块)
app.post('/admin/movie/new', function (res, req) {
var id = res.body.movie._id;
var movieObj = res.body.movie;
var _movie;
if (id !== 'undefined') {
Movie.findById(id, function (err, movie) {
if (err) {
console.log(err);
}
_movie = _.extend(movie, movieObj);
_movie.save(function (err, movie) {
if (err) {
console.log(err);
}
res.redirect('/movie/' + movie._id);
});
});
} else {
_movie = new Movie({
doctor: movieObj.doctor,
title: movieObj.title,
country: movieObj.country,
language: movieObj.language,
year: movieObj.year,
poster: movieObj.poster,
summary: movieObj.summary,
flash: movieObj.flash
});
_movie.save(function (err, movie) {
if (err) {
console.log(err);
}
res.redirect('/movie/' + movie._id);
});
}
});
项目地址: https://github.com/xjchenhao/Learn/tree/master/nodejs/%E7%AB%99%E7%82%B9%E5%BB%BA%E8%AE%BE/imooc
myjimh
9 years, 11 months ago