IONIC- No 'Access-Control-Allow-Origin' header is present

0

I developed an Ionic application, and I have several requests to PHP files, which return data. this works perfect. Now, when I want to recover a json file with $http.get , I get the following error.

Failed to load http://www.xxxxxx.com/ea/json/categories.json:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'file://' is therefore not allowed access.

I add code to them, and I thank them for the help they can give me.

var armo = 'http://www.xxxxxx.com/ea/json/categories.json';
    $http.get(armo).success(function(response) {
        $scope.categories = response;
    });
    
asked by Guille 21.10.2017 в 23:28
source

2 answers

2

Good, you need to configure an ionic proxy in the ionic.config.json file:

  "proxies": [
    {
      "path": "/json",
      "proxyUrl": "http://xxxx.com/json/"
    }
  ]

and an example consuming the api

  getAllPosts() {
    return new Promise(resolve => {
      this.http.get('/json/posts')
        .map(res => res.json())
        .subscribe(data => {
          this.data = data;
          resolve(this.data);
        });
    });
  }

try and tell us.

    
answered by 22.10.2017 в 02:03
0
  

No 'Access-Control-Allow-Origin' header is present on the requested   resource.

This message means that your PHP application has not been configured to accept requests from external applications, if you want to debug you can use a plugin in chrome to eliminate these problems or POSTMAN which is an application to test APIs and verify your URLs where you request or send resources but I strongly recommend that you configure your application to accept external requests.

    
answered by 15.12.2017 в 03:05