简体   繁体   English

我无法使用 js node express 将数据传递到另一个 html 页面

[英]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.

相关问题 如何通过 onclick 和 node.js 将数据从一页传递到另一页并表达? - How to pass data from one page to another by onclick with node.js and express? 我可以将数据从Spring引导控制器传递到html页面,但是如何使用Java Script访问数据? - I am able to pass the data from Spring boot controller to html page, but how do I access the data in Java Script? 如何在HTML(通过节点JS / Express)页面中显示和设置JSON数据样式 - How do i display & style JSON data in my HTML (via node JS/Express) page 我无法使用jQuery将html文本框值传递给webservice - i am not able to pass the html textbox values to webservice using jquery 我试图将一些表单数据从一个html页面传递到另一个页面 - I am trying to pass some form data from one html page to another 为什么我无法通过 Html 使用 Js 将数据写入 Firebase? - Why Am I Not able to Write Data To Firebase using Js via Html? 如何仅使用JavaScript将表单数据从一个HTML页面传递到另一HTML页面? - How do I pass form data from one HTML page to another HTML page using ONLY javascript? 我无法重定向到 Node.js API 中的 HTML 页面 - I am unable to redirect to a HTML page in Node.js API 如何使用Node.js和Express不断更新数据到页面? - How to constantly update data to a page using Node.js and Express? 在使用 pkg 打包 node-express 应用程序时,我无法渲染 static 图像 - I am not able to render static images while packaging node-express app using pkg
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM