如何从jQuery渲染ejs? [英] How to render ejs from jQuery?

查看:256
本文介绍了如何从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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆