【发布时间】: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