本文介绍了如何从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?
发布评论