简体   繁体   English

NodeJS 响应不被 express 或 bodyparser 解析

[英]NodeJS response is not parsed by express or bodyparser

const express = require('express');
const bodyParser = require('body-parser');

const app = express();

const adminRoutes = require('./routes/admin');
const shopRoutes = require('./routes/shop');
// app.use(express.urlencoded({extended:false}));
// app.use(express.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json())


router.get('/add-product', (req, res, next) => {

    res.send('<form action="/product" method="POST"><input type="text" id="fname" name="fname"><br><input type="submit" value="Submit"></form>')
})

the response isn't parsed.. I tried 1k things.. Nothing works... i still receive undefined i tried both variants **app.use(bodyParser.urlencoded({extended:true})); and app.use(express.urlencoded({extended:false})); + app.use(bodyParser.json()) and app.use(express.json());**响应未解析..我尝试了 1k 东西..没有任何效果...我仍然收到 undefined 我尝试了两种变体**app.use(bodyParser.urlencoded({extended:true})); and app.use(express.urlencoded({extended:false})); + app.use(bodyParser.json()) and app.use(express.json());** **app.use(bodyParser.urlencoded({extended:true})); and app.use(express.urlencoded({extended:false})); + app.use(bodyParser.json()) and app.use(express.json());** **app.use(bodyParser.urlencoded({extended:true})); and app.use(express.urlencoded({extended:false})); + app.use(bodyParser.json()) and app.use(express.json());** What's to do? **app.use(bodyParser.urlencoded({extended:true})); and app.use(express.urlencoded({extended:false})); + app.use(bodyParser.json()) and app.use(express.json());**怎么办? thank you in advance先感谢您

you should have app.get and not router.get See here你应该有app.get而不是router.get这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM