當(dāng)前位置:
首頁(yè) >
No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问异常
發(fā)布時(shí)間:2024/9/19
44
豆豆
生活随笔
收集整理的這篇文章主要介紹了
No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问异常
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
前言
- 這是瀏覽器的安全功能導(dǎo)致的,從客戶端/前端是解不開(kāi)的。
- 這個(gè)問(wèn)題必須從服務(wù)端才能解決。所以,這里說(shuō)的是服務(wù)端怎么處理。
接口是自有的
在HTML中,添加 meta 標(biāo)簽
<meta http-equiv="Access-Control-Allow-Origin" content="*" />或,在response對(duì)象中,添加 header
response.setHeader("Access-Control-Allow-Origin", "http://www.domain1.com");或,修改接口返回值,使其支持jsonp
jsonP說(shuō)白了,就是在json字符串外面包上一個(gè):參數(shù)名稱+左右括弧!
返回的json串形式須為callback({0})、showData({0})等,前端使用jsonp調(diào)用接口即可。
接口是第三方的,或接口不方便修改
再另提供一個(gè)接口,使用代理模式調(diào)用原接口
總結(jié)
以上是生活随笔為你收集整理的No 'Access-Control-Allow-Origin' header is present on the requested resource', 跨域访问异常的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Nothing OS 2.5 公测版发布
- 下一篇: nginx http proxy 反向代