所以我使用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