ajax跨域(No 'Access-Control-Allow-Origin' header is present on the requested resource)
2017-07-19 15:25
513 查看
一、跨域问题:
eg:在A网站中,我们希望使用Ajax来获得B网站中的特定内容。如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题。你可以理解为两个域名之间不能跨过域名来发送请求或者请求数据,否则就是不安全的。跨域访问违反了同源策略。
总而言之,同源策略规定,浏览器的ajax只能访问跟它的HTML页面同源(相同域名或IP)的资源。
二、解决方案:
1.Get:
加上:dataType:'jsonp'
2.Post:
(1)web.config中加:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>3.参考文章:
(1)http://blog.csdn.net/zhoucheng05_13/article/details/53580683
(2)https://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource
eg:在A网站中,我们希望使用Ajax来获得B网站中的特定内容。如果A网站与B网站不在同一个域中,那么就出现了跨域访问问题。你可以理解为两个域名之间不能跨过域名来发送请求或者请求数据,否则就是不安全的。跨域访问违反了同源策略。
总而言之,同源策略规定,浏览器的ajax只能访问跟它的HTML页面同源(相同域名或IP)的资源。
二、解决方案:
1.Get:
加上:dataType:'jsonp'
2.Post:
(1)web.config中加:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>3.参考文章:
(1)http://blog.csdn.net/zhoucheng05_13/article/details/53580683
(2)https://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource
相关文章推荐
- ajax跨域获取php文件数据报错:No 'Access-Control-Allow-Origin' header is present on the requested resource.”
- ajax跨域请求:No 'Access-Control-Allow-Origin' header is present on the requested resource
- js跨域访问,no 'access-control-allow-origin' header is present on the requested resource
- 解决 js ajax跨域访问报“No 'Access-Control-Allow-Origin' header is present on the requested resource.”错误
- 跨域问题:No 'Access-Control-Allow-Origin' header is present on the requested resource.
- vue axios 遇到“No 'Access-Control-Allow-Origin' header is present on the requested resource.”的问题
- No 'Access-Control-Allow-Origin' header is present on the requested resource.一种解决思路
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- No 'Access-Control-Allow-Origin' header is present on the requested resource
- 本地Ajax跨域访问 No 'Access-Control-Allow-Origin' header is present on the requested resource.
- No 'Access-Control-Allow-Origin' header is present on the requested resource.'Ajax跨域访问解决方案
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 解决Vue请求 ‘No 'Access-Control-Allow-Origin' header is present on the requested resource’错误
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 跨域问题:“No 'Access-Control-Allow-Origin' header is present on the requested resource”
- "No 'Access-Control-Allow-Origin' header is present on the requested resource" 问题
- “No 'Access-Control-Allow-Origin' header is present on the requested resource”
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
- 解决“No 'Access-Control-Allow-Origin' header is present on the requested resource”
- 解决“No 'Access-Control-Allow-Origin' header is present on the requested resource.”