Nodejs + ExpressJS + Jade + Post无渲染

时间:2012-03-20 15:09:30

标签: jquery node.js pug express

1˚ - 客户:

$.ajax({
    type: 'POST',
    data: data,
    url: '/someposturl',
    success: function (data) {
        console.log('success');
        // $('body').html(data); // i don't want it, but if not so, nothing happens (render) 
    }
});

2˚ - 服务器:

app.get('/criptografar', function (req, res) {
    console.log(req.something);
    res.render('somepage', {
        somevar: withsomevalue
    });
    //-I want this to work like a normal post
});

3˚ - 客户 - > 'somepage' - 没有在客户端中呈现:

$('body').html(data); // i don't want it, but if not so, nothing happens (render)

或者

$('html').html(data); // i don't want it, but if not so, nothing happens (render) <- Jade Layout error.

1 个答案:

答案 0 :(得分:-1)

因为您是从客户端$.ajax拨打的。 如果你从服务器端调用它,它会很好用

要从服务器端调用页面调用URL,您应将其添加到表单

form(role="form" method="POST")

请参阅这个问题。 Express.js Won't Render in Post Action