[英]External web service redirects the user and posts data to my callback URL. How do I render the posted data to the user in an Express/Next.js app?
Any help would be hugely appreciated! 任何帮助将不胜感激! Been stuck on this for a few days. 坚持了几天。
I have an Express/Next.js app where: 我有一个Express / Next.js应用程序,其中:
So now I have the user on a mysite.com/payment-complete
route but also want to display the data that was sent back. 因此,现在我使用户处于mysite.com/payment-complete
路径上,但也想显示发送回的数据。
I have an app.post
endpoint to successfully grab the data: 我有一个app.post
端点可以成功获取数据:
app.post("/payment-complete", async (req, res) => {
const transactionID = req.body.trans_id;
});
How would I pass the data to the user who is already on that route? 如何将数据传递给已经在该路由上的用户? Or pass the data before the page is rendered? 还是在呈现页面之前传递数据?
The flow of data is third party > my server > user and I'm not sure how to make this work. 数据流是第三方>我的服务器>用户,我不确定如何使它工作。
I'd be grateful for any help/direction with this. 如果有任何帮助/指导,我将不胜感激。
If anyone comes across this - the problem was that in Express (and other languages) you can't redirect or render a view for an AJAX POST request but you can if the POST request is coming from a submitted html form. 如果有人遇到这-问题是,在快车(和其他语言),你不能重定向或渲染一个AJAX POST请求的视图,但你可以 ,如果POST请求是从提交的HTML表单来的。 The web service was in fact POST-ing the data and redirecting my users with a form and so I could render a view. 实际上,Web服务正在发布数据,并使用表单重定向用户,因此我可以呈现视图。
Following code worked using Handlebars templating engine to send the render. 以下代码使用Handlebars模板引擎发送渲染。
router.post("/payment-ok", async (req, res) => {
const transactionID = req.body.trans_id;
return res.render("rendertest", { id: transactionID });
});
Should also possibly work with app.render
to send a Next.js view instead, but I wanted to render from a separate routes file. 应该也可以与app.render
一起发送Next.js视图,但是我想从单独的路由文件中进行渲染。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.