0

好吧,我就那么远:

app.get('/mypartial', function (req. res) {
    res.render('mypartial', {layout: false, data: data});
});

这会用数据渲染出我的翡翠并将其作为 html 发送给客户端

现在我需要通过 js 获取它并使用

$('#idofparentelementofyourpartial').html(responseHTML);

所以我需要类似的东西:

//// Pseudocode
var locat = window.location.pathname;
on locat change{

    prevent default // because i want to use the ajax call (not standart browser call)

    ajax({
        url: locat,
        type: "GET",
        dataType: "json",
        success: $('#idofparentelementofyourpartial').html(data);
    });
}

奇怪的是“布局:假”仍然试图渲染一些东西:我希望它只是把东西放入 dom

4

1 回答 1

1

您可以查看 jQuery load()以将部分 html 加载到定义的容器中。

ajax({
    url: locat,
    type: "GET",
    dataType: "json",
    success: $('#idofparentelementofyourpartial').html(data);
});

数据类型 JSON 不是您想要的。

于 2013-06-17T13:27:05.653 回答