angularjs – IONIC,Access-Control-Allow-Origin

前端之家收集整理的这篇文章主要介绍了angularjs – IONIC,Access-Control-Allow-Origin前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试使用此代码发送带有$http(angular)的http请求:
$http({
              method: 'GET',url: 'http://192.168.0.17:9000',header: {'Access-Control-Allow-Origin': "*"},}).then(getEventsSuccess,getEventsError);

但这不起作用,我在Web控制台中出现此错误

XMLHttpRequest cannot load http://192.168.0.17:9000/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.

你有解决方案吗 ?

由于浏览器中实现了一种称为Same Origin Policy的安全机制,您会看到此错误.

基本上,它是由于您的网页尝试访问驻留在与网页本身不同的主机,端口或方案(HTTP / HTTPS /文件等)上的服务器上的资源而引起的.

解决此问题,您可以执行以下操作之一:

>从您尝试访问的服务器提供网页.如果您的网页网址为http://192.168.0.17:9000/X.html,则您的请求应该会成功,错误就会消失.
>为从服务器发送的响应添加一个特殊标头,称为Access-Control-Allow-Origin.

在这里阅读更多:
https://en.wikipedia.org/wiki/Same-origin_policy
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

原文链接:https://www.f2er.com/angularjs/143326.html

猜你在找的Angularjs相关文章