当前位置:
首页 >
No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问异常
发布时间:2024/9/19
51
豆豆
生活随笔
收集整理的这篇文章主要介绍了
No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问异常
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
前言
- 这是浏览器的安全功能导致的,从客户端/前端是解不开的。
- 这个问题必须从服务端才能解决。所以,这里说的是服务端怎么处理。
接口是自有的
在HTML中,添加 meta 标签
<meta http-equiv="Access-Control-Allow-Origin" content="*" />或,在response对象中,添加 header
response.setHeader("Access-Control-Allow-Origin", "http://www.domain1.com");或,修改接口返回值,使其支持jsonp
jsonP说白了,就是在json字符串外面包上一个:参数名称+左右括弧!
返回的json串形式须为callback({0})、showData({0})等,前端使用jsonp调用接口即可。
接口是第三方的,或接口不方便修改
再另提供一个接口,使用代理模式调用原接口
总结
以上是生活随笔为你收集整理的No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问异常的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Nothing OS 2.5 公测版发布
- 下一篇: nginx http proxy 反向代