[英]I am not able to pass data to another html page using js node express
screenshot of receipt page When I click the submit button the data doesn't pass to receipt html file.收据页面的屏幕截图当我单击提交按钮时,数据不会传递到收据 html 文件。 The receipt page is showing but the name is not showing.
收据页面显示,但名称未显示。
var bodyParser = require('body-parser');
var myApp = express();
myApp.use(bodyParser.urlencoded({extended:false}));
myApp.use(bodyParser.json());
var myApp = express();
myApp.set('views',path.join(__dirname,'views'));
myApp.use(express.static(__dirname+'/public'));
myApp.set('view engine','ejs');
myApp.use(express.json());
myApp.get('/',function(req,res){
res.render('purchase');
});
myApp.get('/printReceipt',function(req,res){
res.render('purchase')
});
myApp.post('/printReceipt', (req,res) => {
const name = req.body.name;
res.render('receipt', {
name: name,
});
});
purchase ejs file购买ejs文件
//purchase.ejs
<form method="POST" action="/printReceipt">
<td><input type="text" name="name" id="name" onblur="checkName()"></td>
<td colspan="2"><input type="submit" name="submit" value="submit" ></td>
</form>
receipt ejs file收据ejs文件
//receipt.ejs
<tr align="center">
<td>Name:</td>
<td>:</td>
<td align="right"><%= name %></td>
U need to check your purchase.ejs file.你需要检查你的 purchase.ejs 文件。
Check the form where you have Method, action, u should also add the enctype, which is the content type.检查您有方法、操作的表单,您还应该添加 enctype,即内容类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.