[英]How to render jade template and call that in a div using jquery?
I am trying to load a jade page using the jQuery .load
function. 我正在尝试使用jQuery .load
函数加载一个翡翠页面。 I have a div in index page where i want to load the other jade template when an anchor is clicked. 我在索引页面中有一个div,单击锚点时我想在其中加载其他玉模板。
Jquery code is mentioned below. jQuery代码在下面提到。
$(document).ready(function(){
$('.navsub').click(function(e) {
e.preventDefault();
var page = $(this).attr('href');
var pageout = $.get(page);
if (page=='#')
return false;
else
alert("working");
$('#content_contain').load(pageout);
});
});
and now rendering the page in app.js, rendering code in app.js is mentioned below 现在在app.js中渲染页面,下面提到在app.js中渲染代码
app.get('/somepage', function (req, res) {
var some = res.render('somepage', { title: 'someotherpage' });
res.send(some);
});
Now the question is how do i render the jade template which will be called when anchor will be clicked and call it inside a div. 现在的问题是,我如何渲染单击锚点并在div内调用它时将调用的玉模板。
The jQuery code above works fine if the page extension is .html
or .php
, but not with .jade
. 如果页面扩展名为.html
或.php
,但不适用于.jade
,则上面的jQuery代码可以正常工作。
Can someone explain why this doesn't work? 有人可以解释为什么这行不通吗? I'm using node.js and express.js. 我正在使用node.js和express.js。
res.render
doesn't return anything, but takes a callback. res.render
不返回任何内容,但会进行回调。 So do this instead: 因此改为:
res.render('somepage', { title: 'someotherpage' }, function(err, some){
if (err) return next(err);
res.send(some);
});
在index.js中提到路由并重新启动应用程序对我来说解决了这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.