我在我的節點後端服務器驗證碼:AngularJS HTTP POST無法與節點服務器的工作
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
而這是API,即我要打電話:
router.post('/update/:_id', function(req, res, next) {
console.log("req.body:" + req.body);
}
這是我的帖子請求通過角1:
var data = {something: "something"}
var url = 'http://localhost:8081/update/5982168b399ccf32ad75ce2e';
$http({
withCredentials: false,
method: 'POST',
url: url,
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: data
})
.then(function (response) {
if (response.data) {
console.log("Post Data Submitted Successfully!");
}
}, function (response) {
console.log("Error status: " + response.status)
});
我正在使用Angular 1.6.1版本。
我已經嘗試了一切,並瀏覽了無數帖子,但沒有人幫助我。我可以看到身體經歷。但是我在節點端後端得到了undefined req.body
。
任何幫助,將不勝感激。
謝謝。
更改內容類型的應用程序/ json – Vivz
向你展示app.js(你調用'app.use'和路由)。 – alexmac
歡迎來到Stack Overflow!尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。請參閱:如何創建[mcve]。使用「編輯」鏈接來改善你的*問題* - 不要通過評論添加更多信息。謝謝! – GhostCat