HTTP request works on php but not on JS - CORS rule [duplicate]
Clash Royale CLAN TAG#URR8PPP
HTTP request works on php but not on JS - CORS rule [duplicate]
This question already has an answer here:
i have the following problem:
I am using an API, which has activated the 'same-roigin-rule', so that no client with a different origin-address can fetch data from the API. When i make requests on my lokal dev-deployment, via php cURL, i can fetch data, on localhost. If i try to make an ajax request from my JS code on to the same URL, i get the CORS error (same-origin-rule is active [...]).
The API requires HTTPs basic authentification, which i pass (via username and password or token from API response).
Now my question is why i can do the request via php (as i say my php server is local on my computer, so a different origin i guess...) but not via JS?
Thanks for you attention
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
See the section headed "Why the Same Origin Policy only applies to JavaScript in a web page" on this answer
– Quentin
Aug 10 at 11:01
1 Answer
1
This is a CORS issue, and it is a feature of your browser that's why an http request made with PHP or Curl does not incur in this problem.
Doc: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
server to server is not restricted. CORS is a browser security feature
– charlietfl
Aug 10 at 10:59