学习是一个逐步发现自己无知的过程!

开发中跨域问题解决

当实现前后端分离,前端调用接口,浏览器给出的错误

Access to XMLHttpRequest at 'http://192.168.31.30:8000/Host/' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

No 'Access-Control-Allow-Origin' header is present on the requested resource.
意思就是说,所请求的资源没有Access-Control-Allow-Origin

  • 带上标头-即可解决
get.addHeader(  "Access-Control-Allow-Origin","*");//允许所有来源访同
get.addHeader(  "Access-Control-Allow-Method","POST,GET");//允许访问的方式
  • 使用浏览器插件快速解决

file

插件就帮我们处理好了

file

赞(0)
未经允许不得转载:劉大帥 » 开发中跨域问题解决

你的评论可能会一针见血! 抢沙发

登录

找回密码

注册