0
I는 서버 측에서 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>