我的API无法找到我的帖子参数 这是代码:
var express = require("express");
var bodyParser = require('body-parser');
var redis = require ('redis');
var tools = require('./Read');
var app = new express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
client= redis.createClient();
app.get("/Json", function(req,res){
let b = req.query.Menù;
var secondomenu = new tools.Menu("secondo","secondo",2);
var stringa="";
var a = b.toString().split('p');
let ciao =new tools.Menu(a[0],a[1],a[2]);
let c =[];
c.push(ciao);
c.push(secondomenu);
for (var i =0; i<c.length; i+=1)
{
stringa += retMen(c[i]);
}
client.hset("hash key", "Menu1",JSON.stringify(c), redis.print);
res.send(stringa);
});
app.post("/Save", function(res,req){
var guid = req.body.guid;
var idMenu = req.body.idMenu;
var Menu = req.body.Menu;
client.hset(guid, idMenu, Menu, redis.print);
res.send("Tutto OK");
})
function retMen (Menu) {
return (Menu.IdMenù+ " "+ Menu.desc+ " " +Menu.Vote);
};
app.listen(11100);
这就是错误
监听ws://127.0.0.1的调试器:29026 / e0f09df5-7d1d-4356-bec8-c2a4becabc96 TypeError:无法读取未定义的属性'guid' 的application.js:630
有人能帮助我吗?
答案 0 :(得分:0)
app.post("/Save", function(req,res)
{
var guid = req.body.guid;
var idMenu = req.body.idMenu;
var Menu = req.body.Menu;
client.hset(guid, idMenu, Menu, redis.print);
res.send("Tutto OK");
})
req,res而不是res,req