我試圖找回我從我的主頁傳遞的javascript index.ejs在路由的功能/ index.js如何檢索通過node.js中的.ajax請求傳遞的數據?
index.ejs
$(".user-create-btn").click(function(e){
$.ajax({
url: "https://stackoverflow.com/users/create/",
data: {username: "John123"},
type: "post",
dataType : "json",
success: function(result) {
console.log("test")
}
});
e.preventDefault(e);
location.reload();
});
路線/索引的數據。 JS
/*Create new user*/
router.post('/users/create', (req, res) => {
//how can i retrieve the the data of the username here?
models.User.create({
username: username,
})
});
我想你想https://github.com/expressjs/body-parser – Sukima