客戶端空的,這是我所發生的事情:要求身體總是在POST
function saveGrades() {
$.post("/savegrades", {classIndex: "classIndexId"}); }
服務器端:
router.post('/savegrades', stormpath.loginRequired, function(req, res) {
console.log("Class index: " + req.body.classIndex);
console.log(req.body);
res.send(200);
});
我bodyParser
設置如下:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
無論我嘗試過什麼,req.body
都是空的,並且沒有classIndex
。我做錯了什麼?爲什麼數據沒有發佈到服務器?
編輯:對於鏈接的問題,我經歷了幾乎所有相關的答案,無法找到解決方案。看起來這些數據永遠不會被髮送到服務器。當我用調試器檢查它時,主體總是空的。
http://stackoverflow.com/questions/5570747/jquery-posting-json –
@發送AndreyPopov我無法用這個問題的答案來解決我的問題。 – iamtesla
我會試着鏈接一個:)你見過這個(尤其是奧利的回答)? http://stackoverflow.com/questions/5529685/post-doesnt-send-data-as-json-but-as-x-www-form-urlencoded-instead – Antenka