Javascript 更改使用Express 4呈现视图的url
我有一个post请求,问题是当我呈现我的视图时,它被呈现到Javascript 更改使用Express 4呈现视图的url,javascript,node.js,express,Javascript,Node.js,Express,我有一个post请求,问题是当我呈现我的视图时,它被呈现到/link/123我希望该视图呈现到/anotherlink 我本可以使用res.redirect('/anotherlink')但我需要呈现不同的数据 app.post('/link/:id',function (req, res, next){ res.render('products', { data : 'help please' }); }); 我发现我的问题出现了转机,所以我使用了res.status(2
/link/123
我希望该视图呈现到/anotherlink
我本可以使用res.redirect('/anotherlink')但我需要呈现不同的数据
app.post('/link/:id',function (req, res, next){
res.render('products', {
data : 'help please'
});
});
我发现我的问题出现了转机,所以我使用了
res.status(200).send('ok'),而不是res.render
代码>
然后,当用户单击submit按钮时,我使用ajax表单发送一个模式,通知更新已经完成
$('#update-form').ajaxForm({
beforeSubmit :...
},
success : function(responseText, status, xhr, $form){
if (status == 'success') $('.modal-alert').modal('show');
},
error : ...
});
当用户单击“确定”时,他将被发送到/anotherlink
$('.modal-alert #ok').click(function(){
setTimeout(function(){window.location.href = '/anotherlink';}, 200)});
}
我找到了一个更好的解决方案,即在视图中更改url而不重新加载:window.history.pushState(“,”,“/wantedLink”);