好吧,我就是这么远:
app.get('/mypartial', function (req. res) {
res.render('mypartial', {layout: false, data: data});
});
这会将我的jade渲染出来并将其作为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);
});
}
奇怪的是,“layout:false”仍然试图渲染一些东西:我希望它只是将东西放入dom中
答案 0 :(得分:1)
您可以查看jQuery load()以将部分html加载到已定义的容器中。
ajax({
url: locat,
type: "GET",
dataType: "json",
success: $('#idofparentelementofyourpartial').html(data);
});
数据类型JSON不是您想要的。