In nodejs/.ejs
file, I can display the user name as follows:
<% if (!user) { %> <h2>Welcome! Please <a href="https://www.tuicool.com/login" >Login</a>.</h2> <% } else { %> <h2>Hello, <%= user.displayName %>.</h2> <% } %>
How to do the same in html page.
Problem courtesy of: Narendra Reddy Lingam
Solution
I assume you a static
html page. The short answer is that you can’t– that’s what makes it a static page.
The longer answer is that if you have that html page include some JavaScript that then performs an AJAX call to the server to fetch the username, you can. Look into jQuery $.get
function if you’re choosing this approach.
Solution courtesy of: juanpaco
Discussion
There is currently no discussion for this recipe.
This recipe can be found in it’s original form on Stack Over Flow
.
注意:本文来自Node.js Recipes。本站无法对本文内容的真实性、完整性、及时性、原创性提供任何保证,请您自行验证核实并承担相关的风险与后果!
CoLaBug.com遵循[CC BY-SA 4.0]分享并保持客观立场,本站不承担此类作品侵权行为的直接责任及连带责任。您有版权、意见、投诉等问题,请通过[eMail]联系我们处理,如需商业授权请联系原作者/原网站。
CoLaBug.com遵循[CC BY-SA 4.0]分享并保持客观立场,本站不承担此类作品侵权行为的直接责任及连带责任。您有版权、意见、投诉等问题,请通过[eMail]联系我们处理,如需商业授权请联系原作者/原网站。