使用此代碼我創建了一個函數,該函數創建一些JSON數據並將其發送到server.js(我的節點服務器)。發送到節點服務器時發生更改的JSON對象
function deleteEmail(i) {
emailObj.splice(i, 1);
var general = {};
var table = []
general.table = table;
for (var i = 0; i < emailObj.length; i++) {
var dataHtml = emailObj[i].html;
var html = {
"html": dataHtml
}
general.table.push(html);
}
console.log(JSON.stringify(general));
$.post("email2", general);
}
server.js內的代碼來捕獲JSON數據是這樣的:
app.post("/email2", function(req, res){
console.log(req.body);
});
這裏是由功能創建併發送至server.js JSON數據:
{"table":[{"html":"<b>ID email:</b> #1481145671503<br><b>Form journey:</b> General<br><b>Work Request Title:</b> <br><b>Data Request:</b> <br><b>Request By:</b> <br><b>Department:</b> <i>not specified</i><br><b>Business Owner:</b> <br><b>Contact Details:</b> <br><b>Request Overview:</b> <br><b>Platform Impacted:</b> undefined<br><b>Business Objectives:</b> <br><b>Business Benefits Justifications:</b> <br><b>Project Drive:</b> <br><b>Additional Information:</b> <br>"},{"html":"<b>ID email:</b> #1481214851188<br><b>Date:</b> Thu Dec 08 2016 16:34:11 GMT+0000 (GMT)<br><b>Form journey:</b> General<br><b>Work Request Title:</b> <br><b>Data Request:</b> <br><b>Request By:</b> <br><b>Department:</b> <i>not specified</i><br><b>Business Owner:</b> <br><b>Contact Details:</b> <br><b>Request Overview:</b> <br><b>Platform Impacted:</b> undefined<br><b>Business Objectives:</b> <br><b>Business Benefits Justifications:</b> <br><b>Project Drive:</b> <br><b>Additional Information:</b> <br>"}]}
這裏是服務器正在接收的JSON數據:
{ 'table[0][html]': '<b>ID email:</b> #1481145671503<br><b>Form journey:</b> General<br><b>Work Request Title:</b> <br><b>Data Request:</b> <br><b>Request By:</b> <br><b>Department:</b> <i>not specified</i><br><b>Business Owner:</b> <br><b>Contact Details:</b> <br><b>Request Overview:</b> <br><b>Platform Impacted:</b> undefined<br><b>Business Objectives:</b> <br><b>Business Benefits Justifications:</b> <br><b>Project Drive:</b> <br><b>Additional Information:</b> <br>',
'table[1][html]': '<b>ID email:</b> #1481214851188<br><b>Date:</b> Thu Dec 08 2016 16:34:11 GMT+0000 (GMT)<br><b>Form journey:</b> General<br><b>Work Request Title:</b> <br><b>Data Request:</b> <br><b>Request By:</b> <br><b>Department:</b> <i>not specified</i><br><b>Business Owner:</b> <br><b>Contact Details:</b> <br><b>Request Overview:</b> <br><b>Platform Impacted:</b> undefined<br><b>Business Objectives:</b> <br><b>Business Benefits Justifications:</b> <br><b>Project Drive:</b> <br><b>Additional Information:</b> <br>' }
它爲什麼這樣做,我怎麼能發送它也保持完全相同的格式和數據,並解釋它由server.js。
謝謝
你可以檢查幾件事情 - 明確設置連續在發送請求時,在jquery中將ent類型轉換爲'application/json',並檢查node.js應用程序中的body parser中間件。看來這個問題最有可能在這兩個地方之一。 –