簡體   English   中英

如何讓我的瀏覽器在登錄 POST 請求后呈現“成功”頁面?

[英]How do I get my browser to render a "success" page after a login POST request?

Res.sendFile 有效,但我的 localhost:3000 不會自動更改為 localhost:3000/success.html

當我點擊提交時,如何讓我的瀏覽器顯示 localhost:3000/success.html?

const express = require('express'). // Include ExpressJS
const app = express(). // Create an ExpressJS app
const bodyParser = require('body-parser'); // Middleware
const path = require("path")

app.use(bodyParser.urlencoded({ extended: false }));

// Route to Homepage
app.get('/', (req, res) => {
  res.sendFile(__dirname + '/static/index.html');
});

// Route to Login Page
app.get('/login', (req, res) => {
  res.sendFile(__dirname + '/static/login.html');
});

app.post('/login', (req, res) => {
  // Insert Login Code Here
  let username = req.body.username;
  let password = req.body.password;
  res.sendFile(path.join(__dirname,'success.html'));
});

const port = 3000 // Port we will listen on

// Function to listen on the port
app.listen(port, () => console.log(`This app is listening on port ${port}`));**strong text**

嘗試在您的情況下使用express redirect res.redirect('path')

res.redirect('success.html');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM