前端ajax跨域问题及基于node的跨域解决方案No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

百度了半天都说是跨域问题,
解决办法:
设置请求头解决跨域
res.setHeader('Access-Control-Allow-Origin', '*'); //设置请求头解决跨域
app.get('/song_sheet',function(req,res){
connection.query('select * from song_sheet',function(error,results,fields){
res.setHeader('Access-Control-Allow-Origin', '*'); //设置请求头解决跨域
res.send(results)
// console.log(results)
console.log(error)
})
})
解决问题

参考自:https://blog.csdn.net/weixin_45014444/article/details/96734242

浙公网安备 33010602011771号