gpt4 book ai didi

javascript - 我的邮寄路线有问题吗?

转载 作者:行者123 更新时间:2023-11-30 21:55:28 24 4
gpt4 key购买 nike

所以我将 sequelize 用于一个简单的 CRUD 样式网页。我的问题是我能够将输入字段中键入的数据发送到 mysql workbench,并将其存储在表中,但在网页本身上没有任何反应。

  //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);
});
});

在此先感谢您的帮助!

最佳答案

webpage itself nothing happens

什么页面?您成功的数据库操作告诉应用程序重定向到 /dashboard 但您也在尝试发送 JSON 数据。我很惊讶您的应用程序中没有出现 header 错误。您不能同时重定向到另一条路线并向客户端发送数据。

您需要重定向到 /dashboard,然后您的仪表板路由必须再次查询数据才能返回显示。

关于javascript - 我的邮寄路线有问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45384334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com