如何从jQuery渲染ejs?

编程入门 行业动态 更新时间:2024-10-21 22:55:38
本文介绍了如何从jQuery渲染ejs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在从API获取数据后呈现文件。

I want to render a file after getting the data from the API.

代码

$(document).ready(function() { $(document).delegate( "#editUser", "click", function() { var userId = $(this).data('id'); $.post("/userProfile",{"userId":userId},function(data, status){ console.log(data); //gets data here //how to render ejs file here with the above data? }); });

ejs file:(sample.ejs)

ejs file: (sample.ejs)

<% include header.html %> <strong>Sample ejs</strong> <ul> <li><%= data.name %> says: <%= data.message %></li> </ul> <% include footer.html %>

如何解决这个问题?

推荐答案

你无法使用你的数据渲染ejs文件用ajax调用eceive。 ejs在服务器端呈现,其中ajax调用发生在客户端。 要解决您的问题,您需要在服务器端获取用户数据并将其发送到ejs文件。

You can't render the ejs file with the data what you receive with ajax call. ejs renders at server side, where as the ajax call happens on the client side. To solve your issue you need to get the user data at server side it self and send it to ejs file.

更多推荐

如何从jQuery渲染ejs?

本文发布于:2023-10-27 15:46:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533826.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery   ejs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!