首页 > 解决方案 > 如何使响应不渲染也不重定向?

问题描述

我提出了一个请求,开发人员可以使用该请求来验证客户请求。我希望当有人提出请求时,只需更改数据库中的验证状态,网页保持不变,只是按钮像 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')
}

})

但我最终得到

即使我使用 res.end 或不显示相同的结果

标签: javascriptnode.jsexpresshttpresponse

解决方案


推荐阅读