【问题标题】:Render .jade with json from ajax GET使用来自 ajax GET 的 json 渲染 .jade
【发布时间】:2016-03-04 13:17:41
【问题描述】:

我为我们的 jQuery、Node、Jade 设置布局,以便在本地服务器上测试我们的 api。

使用这个 jQuery 调用,我试图将返回的 JSON 加载到一个新的 .jade 页面中

block scripts
script.
    $(document).ready(function() {
        $('#getId').click(function() {
            var projId = document.getElementById('projectId').value;
            $.ajax({
                type: 'GET',
                url: '/api/projects/get/' + document.getElementById('projectId').value,
                statusCode: {
                    200: function (res) {
                        res.render('admin/displayOneProject', {layout:'layout', data:JSON.parse(res)})
                    },
                    500: function(res){
                        alert(JSON.parse(res).status);
                    }
                }
            });
        });

    });

我可以确认我的 api 正在返回正确的数据,所以我只需要最后一行来呈现带有我发送的 JSON 的新 .jade 页面。但是,当我运行它时,最后什么也没有发生。

【问题讨论】:

  • 我自己解决了这个问题。混淆了我的客户端/服务器代码。

标签: jquery ajax express pug render


【解决方案1】:

你试过放一个

var redraw_view = function () {
your CODE
then 
$div(#of body).change(redraw_view);

【讨论】:

    猜你喜欢
    • 2017-04-09
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-02
    • 2014-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多