0
私は、サーバー側でvalue2
を変更し、ビューをリフレッシュしている必要があるので、質問は何ですか:のNode.js
私が更新して表示を更新するにはどうすればよいです新しいvalue2
とのみですか?
サーバー:
var express = require("express");
var app = express();
app.set('view engine', 'ejs');
app.set('view cache', false);
app.set('title', 'Test');
var bodyParser=require("body-parser");
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static('public'));
app.get('/', function(req, res, next) {
res.render('test', { value1: 'A', value2: 'B', value3: 'C', value4: 'D' });
});
app.post('/', function(req, res, next) {
// I don't know value1, value3 and value4 :(
// and the Next line doesn't work
res.render('test', { value2: 'X' });
});
app.listen(3001);
クライアント:
<!DOCTYPE html>
<html>
<head>
<title> Hi </title>
</head>
<body>
<form id="update" method="post" action="/" >
<h2> This is Value1 (<%= value1 %>) and This is Value2 (<%= value2 %>) </h2>
<h2> This is Value3 (<%= value3 %>) and This is Value4 (<%= value4 %>) </h2>
<button type="submit" >Change Value2</button>
</form>
</body>
</html>