エクスプレスサーバーとログインページがHTML形式で開発されています(jqueryを使用)。ログインボタンがヒットした後、jQueryがサーバを表現するHTTP getリクエストを起動し、ユーザが検証された後、ユーザは名前、性別、年齢などのデータを含むランディングページにリダイレクトされます(サーバ自体のmongoDBから取得されます)。 res.sendFile
またはres.redirect
を実行すると、応答に必要なビューでパラメータ(名前、年齢、性別)を送信できませんでした。expressおよびnodejsアプリケーションによる応答
のjQuery:
$("#submit").click(function() {
user = $("#email").val();
pass = $("#password").val();
$.post("https://localhost:443/login", {
user: user,
password: pass
}, function(response) {
if (response) {
alert("login success" + response.userName);
}
});
});
HTML:
<form id="grad">
<h1 style="margin-top: -10px; text-shadow: 1px 1px whitesmoke;">Login</h1>
<h3 style="padding-bottom: 30px;font-size: 22px ">Please enter email ID and password.</h3>
<div class="group">
<input type="email" id="email" name="email"><span class="highlight"></span><span class="bar"></span>
<label>Email ID</label>
</div>
<div class="group">
<input type="password" id="password" name="password"><span class="highlight"></span><span class="bar"></span>
<label>Password</label>
</div>
<div class="group">
<input type="submit" id="submit" class="button buttonRed" value="Login" onclick="validateUser()" />
<input type="reset" class="button buttonRed" value="Reset" />
</div>
</form>
エクスプレス:
app.post('/login', function (req, res) {
// some logic to validate user and fetch details, which will be used on view.
res.sendFile('landing**strong text**page.html', { root: "public" });
})
あなたのコードがありません – mike510a