Node.js 我无法通过axios发送数据

Node.js 我无法通过axios发送数据,node.js,axios,Node.js,Axios,无法通过axios获取数据。 下面是前端代码 函数sendData(newData){ post(“/cart/addData”,newData)。然后((res)=>{ 警报(res) }); } 让getBtn=document.getElementById(“cartButton”) getBtn.addEventListener(“单击”,函数(){ 让data=getBtn.dataset.cart; 让newData=JSON.parse(数据); sendData(newData)

无法通过axios获取数据。 下面是前端代码

函数sendData(newData){
post(“/cart/addData”,newData)。然后((res)=>{
警报(res)
});
}
让getBtn=document.getElementById(“cartButton”)
getBtn.addEventListener(“单击”,函数(){
让data=getBtn.dataset.cart;
让newData=JSON.parse(数据);
sendData(newData);
});
当我尝试在服务器端获取它时,它总是将req.body显示为空对象

router.post(“/addData)”,(请求、回复)=>{
控制台日志(req)
});

在后端添加中间件以解析正文:


app.use(express.json())

在后端添加中间件以解析正文:


app.use(express.json())

谢谢它成功了。谢谢它成功了。