javascript - 如何使响应不渲染也不重定向?
问题描述
我提出了一个请求,开发人员可以使用该请求来验证客户请求。我希望当有人提出请求时,只需更改数据库中的验证状态,网页保持不变,只是按钮像 ajax 调用一样被禁用,但没有 ajax。我使用 node 和 mongodb 作为后端,使用 ejs 进行渲染。这是否可能,或者我必须使用用户端 ajax 调用。
router.get('/verifycustomer/:id', redirectHome, async (req, res) => {
try{
const id = req.params.id
if(!id){
req.flash('error_msg', 'Please provide a vlalid id of customer')
return res.redirect('')
}
const customer = await Customer.updateOne({_id:id}, {verificationStatus:true})
if(customer.nModified){
req.flash('error_msg', 'Failed to verify customer Pleas try again.')
return res.redirect('')
}
res.end()
} catch(e) {
console.log(e)
res.render('pages/505Error')
}
})
但我最终得到
解决方案
推荐阅读
- node.js - 套接字 io 客户端无法连接到远程服务器(套接字服务器)
- c# - 使用没有 DATABASE 的 SMO 还原 DB 正在使用错误
- angular - 角度“serviceworker”中的 Razorpay 集成必须是 Web 应用清单中的字典
- node.js - Angular 11 编译目标 es5 导致 JavaScript 堆内存不足问题
- promise - 在 for 中使用 Promise.all() 延迟
- python - subprocess.call 没有命令写入控制台
- php - 将大量 pdf 导入 mPDF 导致 /fopen 失败
- windows - VisualAge cpprbi40.dll 在 Windows 10 版本 20h2 中不起作用
- python-3.x - 我们如何在 docplex 中删除一批约束?
- javascript - 未捕获的类型错误:modal.openModal 不是函数