私はルート/ index.jsnode.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();
});
ルート/インデックス内の機能にはJavaScript index.ejs私のホームページから渡していたデータを取得しようとしています。 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