0

I have developed the Woocommerce ionic app but when i connect the app with live site or server then its gives this error :

Access to fetch at 'https://www.example.co.uk/shop/wp-json/v3/products/categories?filter[meta]=true&filter[variation]=true' 
    from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight
     request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains
     multiple values 'http://localhost:8100, *', but only one is allowed. Have the server send the 
    header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Please see the below screenshots as well : enter image description here

To resolve this error i have also paste the below code on my server .htaccess file :

Header  set Access-Control-Allow-Methods "HEAD, POST, GET, PUT, OPTIONS, PATCH, DELETE"
Header  set Access-Control-Allow-Origin "*"
Header  set Access-Control-Allow-Credentials "true"
Header  set Access-Control-Allow-Headers "X-Accept-Charset,X-Accept,Content-Type,Credentials"

But still it showing the same error.

Before 1 months its working fine. I am using ionic CLI version is : 3.4.0 and npm version is : 6.6.0

dineshkashera
  • 1,442
  • 1
  • 15
  • 26

2 Answers2

0

According to the error message the browser receives the following response header:

Access-Control-Allow-Origin: http://localhost:8100, *

Specifying multiple origins in the response is not allowed and thus you get CORS error.

You should try to understand what makes your server return multiple values. I would:

  1. Try with incognito without any extensions as some extensions could modify this header.
  2. Search in the code and Apache config files for any line with Access-Control-Allow-Origin
Niros
  • 632
  • 5
  • 18
0

This issue mainly occurred from server side try to change you .htaccess file

Like

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
</IfModule> 

Refer ans from htaccess Access-Control-Allow-Origin

paras shah
  • 861
  • 2
  • 9
  • 23
  • Thanks for your reply, I have already set this Header set Access-Control-Allow-Origin "*" in .htaccess file on server. But still it not working, Only shows loading... Banner. – dineshkashera Feb 14 '19 at 10:31
  • Please Check your config.xml file does it has this line else add it – paras shah Feb 15 '19 at 13:31
  • There in no any file with name config.xml , I am using Wordpress and have .htaccess file . Also i have added the above code but still not working. – dineshkashera Feb 16 '19 at 07:35