我目前正在做一个学校项目来制作一个 web 应用程序并且遇到了这个问题。如果没有收到响应(我假设),因为当我使用“res”对象时,它会导致页面显示“无法 POST /editProfile”错误。返回页面并再次提交表单不会显示错误。后端一切正常,数据库中的对象即使在第一次提交表单时也会更新。
这是它的代码..
$.post('/updateName', {username:Uname}, function(res){
if(res.status == 200){
alert("Name Successfully Updated");
window.location.href = "/profile";
}
else{
window.location.href = "/";
}
})
来自控制器的后端代码
exports.update_profile = function(req, res){
cModel.update_profile(req.session.id, req.body, function(result){
res.send({status:200});
});
}
在撰写本文时,我发现在 Microsoft Edge 上运行 web 应用程序时没有问题,但问题出现在 Chrome 上。我现在不确定该怎么做。