Rest API Codeigniter. CORS PROBLEM [SOLVED] |
Hello, I'm working on ReactJS. I'm using React for the front-end part of website, and as backend I'm using Codeigniter with the RestAPI library (https://github.com/chriskacerguis/codeig...restserver).
I'm working on http://localhost:8080 and PHP is on a link (created in hosts file) http://spotalefinale.com. Now, I've a controller: PHP Code: <?php and a sort of jquery ajax request: Code: handleSubmitLogin(e){ (axios works as $.ajax). I'm getting this error: "Failed to load http://spotalefinale.com/a: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access." but I enabled the cors in the controller, as you can see. Now if I enable the CORS with a Chrome extension, it works without any problem. (This is the extension). Which is the problem? Why without enabling the extension the cors doesn't work? Thank you if you have some ideas!
Here is a very good article on it.
Cross-Origin Resource Sharing (CORS) Hope that helps. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Yeah, thank you. I read it, but it doesn't help me too much.
I don't know if it is a "local" problem (I'm running on localhost:8080), maybe is it?
Ok, I tried to host the frontend (reactjs) on a server with an accessible domain, then I tried one request and it doesn't work.
I've always this error: ![]() UPDATE: SOLVED! So, I was using IIS, so I added to my web.config: Code: <httpProtocol> PHP Code: <?php and now it works!
Glad to hear you got it to work.
Please edit your title and add this at the end of it [SOLVED] Enjoy What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |