【问题标题】:Nodejs + ExpressJS + Jade + Post no renderNodejs + ExpressJS + Jade + Post 无渲染
【发布时间】:2012-04-05 01:47:20
【问题描述】:

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.

【问题讨论】:

  • 接下来会发生什么?如您所见,您正在执行 ajax 调用和服务器响应数据。你了解ajax是什么吗? :) 如果您希望它像普通 POST 一样工作,例如可以从服务器返回 URL 并执行 location.href = url;
  • 下次请正确格式化您的代码;虽然其他人可能会很快做到,但让他们做一些您也可以轻松做到的事情并不好。
  • 你应该使用 app.post( 而不是 app.get(

标签: jquery node.js pug express


【解决方案1】:

因为您从客户端从$.ajax 调用它。 如果从服务器端调用它会很好用

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

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

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

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
  • 好的,注意到@Rory-McCrossan
猜你喜欢
  • 1970-01-01
  • 2017-10-20
  • 1970-01-01
  • 2017-09-15
  • 2013-10-23
  • 1970-01-01
  • 1970-01-01
  • 2019-02-09
  • 1970-01-01
相关资源
最近更新 更多