此代码按预期工作
app.get('/:phonenum', (req, res) => {
var source = req.header('user-agent');
var ua = useragent.parse(source);
if (ua.isDesktop) {
res.status(308).redirect(`https://web.whatsapp.com/send?phone=+${req.params.phonenum}`);
}
})
但我尝试向另一条路线发出ajax请求,而不是GET我使用了POST
app.post('/send', (req, res) => {
var source = req.header('user-agent');
var ua = useragent.parse(source);
if (ua.isDesktop) {
res.status(308).redirect(`https://web.whatsapp.com/send?phone=+${req.body.phone}&text=${req.body.msg}`);
}
})
我在chrome控制台中遇到了这个错误。
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
这里有什么问题?