'CORS Problem with React js on my PHP from the scratch API
Hello Guys I have a problem on my PHP API i uploaded my API on this website
"app.infinityfree.net"
whenever I try to access my build in PHP API I get this error
Access to XMLHttpRequest at 'http://*****' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
this is my PHP code for header
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');
header("Access-Control-Allow-Methods: POST, GET");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
takenote: I build a API from the scratch in PHP and my frontend was a localhost. so that my API is public
any idea how to resolve my issue ? it is running this code on my local server
Someone answer me and the domain i use is not possible for API Hosting
Can I ask is there any Free API hosting that can i do Mysql free cloud storing?
I just look up Google Cloud services and GitHub server for my API
It is possible to host may API on GitHub and use Google Cloud services for my AP if do so could please send me a step by step tutorial website
Or any other step what to do so that u can deploy this
I really appreciated if your answer me because it will your answer on my career and also for my School
Thank you in advance!
Solution 1:[1]
It seems that CORS is not supported on InfinityFree.
As stated here, the following things will not work correctly or at all on websites on free hosting:
- AJAX requests from other websites (CORS). AJAX requests are only possible on the same (sub)domain.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | tezzo |