奇怪的問題,我對此沒有任何解釋。我創建 ajax 發布請求
$.ajax({
type: "POST",
url: "/like",
data: {"topic": "123123"},
success: function(dataString) {
console.log('123123');
}
});
或者像這樣:
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/like", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("fname=Henry&lname=Ford");
在服務器端(NodeJs)我有簡單的代碼
app.post('/like', function (req, res) {
console.log(req.body);
res.status(201).send(' 1')
});
我不明白的是,為什么我在發送 ajax 發布請求時一直收到未定義的訊息。

uj5u.com熱心網友回復:
您需要使用正文決議器,請參閱:nodejs.dev/learn/get-http-request-body-data-using-nodejs
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/454964.html
下一篇:連接Ajax序列化資料
