所以我使用sequelize为一个简单的CRUD风格的网页。我的问题是我能够将输入的数据发送到mysql工作台的输入字段,并将其存储在表中,但在网页上本身没有任何反应。我的邮寄路线有问题吗?
//uses var=Posts which contains the fields userName
//and userPosts in my database
var db = require("../models");
// route to create posts
app.post("/api/posts", function(req, res) {
console.log(req.body);
db.Posts.create({
userName: req.body.username,
userPosts: req.body.user_post,
})
.then(function(dbPost) {
res.redirect('/dashboard');
res.json(dbPost);
});
});
在此先感谢您的帮助!
哪个js框架你使用?什么时候触发?一旦你得到回应? – mygeea
我正在使用node.js,handlebars和sequelize。我将页面重定向到用户在输入内容后提交的主页仪表板。如果我将重定向输出,则会跳转到显示以下内容的页面:{ “id”:7, “userName”:“2”, “userPosts”:“asdf”, “createdAt”:“2017- 07-29T01:27:12.000Z”, “updatedAt”: “2017-07-29T01:27:12.000Z” } – onetwothree
尝试取出重定向,看看它是否显示。 – MinusFour