How do I solve this error of the cors in ionic3?

0

I need to fix that error that appears in the app's console.

    
asked by Claudio Navarrete 19.01.2018 в 13:48
source

2 answers

1

1.- You can add a proxy in the ionic.config.json file of your Ionic app to perform tests. In the documentation it tells you how to: service-proxies .

2.- Your server must allow javascript requests from other servers in order to obtain information from the original server. More information on Wikipedia: CORS , Mozilla CORS .

Those are the 2 possible solutions to the restrictions you have to be able to make your requests.

    
answered by 19.01.2018 / 14:24
source
0

Another option would be in your php script to add:

header("Access-Control-Allow-Origin: *");

Or if you are using the slim framework according to the documentation:

$app->options('/{routes:.+}', function ($request, $response, $args) {
    return $response;
});

$app->add(function ($req, $res, $next) {
    $response = $next($req, $res);
    return $response
            ->withHeader('Access-Control-Allow-Origin', 'http://mysite')
            ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
            ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
});

Link to the slim documentation

    
answered by 19.01.2018 в 15:01