【发布时间】:2014-05-12 11:03:48
【问题描述】:
我正在使用 express.js。我想做的只是在单击表格元素后重定向到 html 页面。当前输出是 HTML 源代码 console.log(而不是重定向然后解释为 HTML 页面)
我的点击功能如下(ajax post)
<script>
$(".table").click(function() {
/* Act on the event */
$.ajax({
url: "/selectForm",
type: "POST",
data: {name : "John"},
cache: false,
timeout: 5000,
complete: function() {
//called when complete
console.log('process complete');
},
success: function(data) {
console.log(data);
console.log('process sucess');
},
error: function() {
console.log('process error');
},
});
});
我的 app.post 如下所示;
app.post('/selectForm',function(req,res){
res.redirect('hello.html');
});
我在 chrome javascript 控制台中获得了 HTML 输出,但在浏览器中我没有看到它重定向到 hello.html。
【问题讨论】:
-
我猜你应该在你的
$.ajax请求中插入async: false。然后,您可以根据需要删除timeout。 -
不走运 async :false 。我可以在控制台日志中看到呈现的 html 页面,然后显示“处理成功”和“处理完成”消息。
标签: jquery ajax node.js express