angularjs – 在离子中设置CORS

前端之家收集整理的这篇文章主要介绍了angularjs – 在离子中设置CORS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建我的第一个离子应用程序,但我正在与cors挣扎,我在这个领域没有很多经验,所以这个问题可能看起来很愚蠢.

我无法访问api网站,因此我无法更改任何内容.
这是我用来从api站点获取数据的代码.我已经读过,当使用离子发射器测试时,cors只是一个问题,但我已经尝试构建Android应用程序并将apk转移到我的手机,但它似乎也没有在那里工作(我不能看到我手机上的控制台登录测试它:))

app.controller('VolleyCtrl',function($http,$scope) {
      $scope.wedstrijden = [];
      $http.get('http://www.volleyadmin2.be/services/wedstrijden_xml.PHP?province_id=5&stamnummer=O-0696&format=json')
        .success(function(response) {
          angular.forEach(response,function(child) {
            $scope.wedstrijden.push(child);
          })
        });

  });

解决方法

If you’re using a newer version of Cordova (or the latest Ionic CLI) to develop your app,you may be experiencing http 404 errors when your app tries to make network requests.

这可以通过Cordova Whitelist plugin快速解决.

您可以在Ionic docs: Cordova Whitelist找到更多文档.

解:

在shell /终端中运行以下命令:

ionic plugin add https://github.com/apache/cordova-plugin-whitelist.git

您现在唯一需要做的就是在config.xml中添加一个属性
 文件

< allow-navigation href =“*”/>

猜你在找的Angularjs相关文章