繁体   English   中英

如何在 Node.js 的 HTML 页面上显示 API 响应?

[英]How can I show the API response on an HTML page in Node.js?

如何在 Node.js 的 HTML 页面上显示 API 响应?

这是我的代码:

 res.writeHead(200, {'Content-Type': 'text/html'});
                res.write('Code:'+req.body);
                var temp = req.body;
                console.log(req.body)
                res.write('<script>setTimeout(function () { window.location.href = "http://localhost:63342/untitled/node_rest_shop/api/login_success.html?_ijt=f37kuelpb06k09ooesdrced6ko" + res.body},5000);</script>');

                res.end();

当响应成功时,它应该显示 HTML 的下一页。

当您需要在字符串中插入变量时

在 Javascript 中,它调用Template_literals使用反引号而不是单引号

res.write(`<script>setTimeout(function () { window.location.href = "http://localhost:63342/untitled/node_rest_shop/api/login_success.html?_ijt=f37kuelpb06k09ooesdrced6ko${res.body}"},5000);</script>`);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM