Can't get JSON data with IONIC and Drupal7 as back end

I have created my Rest server with Drupal. My Http request work very well on Postman. But when i try to get the datas on my ionic App, i have this error.

Failed to load http://(url)/rest/article: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.

Please can you help?

I expect you are running this with ionic serve to browser. I think you have a cors issue. Try installing cors extension to Chrome web browser and try to run ionic serve on Chrome.

Do you have local backend? Check these lines (after ) in httpd.conf. I don’t remember which line i added, but it helped me.

Header set Access-Control-Allow-Credentials "true"
SetEnvIf Origin “." allow_origin=$0
Header set Access-Control-Allow-Origin "%{allow_origin}e"
SetEnvIf Access-Control-Request-Method ".
” allow_method=$0
Header set Access-Control-Allow-Methods "%{allow_method}e"
SetEnvIf Access-Control-Request-Headers “.*” allow_headers=$0
Header set Access-Control-Allow-Headers “%{allow_headers}e”

And I think this is just when you are running on web browser. When running on device, it should work just fine.

thank you very much. I downloaded the extension and it’s work very good.

Hi

you may bump into the problem again using Ionic View.

So you know.

Regards

Tom

So what is the best solution?

I say continue with what you are doing and be mindful of it. Android builds did not give me issues. Never tried iOS builds with cors.

Ionic View isnt your end station and you can still try using Ionic View Legacy

And if worst comes to worst you could always build a proxy server in between