How to fix “Cross-Origin Request Blocked” error

I had this problem when I am in the process of migrating my web services files into another server. My web services files on where the third party users connect to my application suddenly stopped working and had this error when connecting to them:


Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at [URL_HERE]
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

What I had done is to add these additional response headers into my receiving files(meaning the one that receives and process the data).


header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET,POST");
header("Access-Control-Allow-Headers:Content-Type");
header("Access-Control-Allow-Credentials:true");

You can see the different kinds of HTTP request methods here
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods and use whatever suits your application needs.

cross-origin request blocked jquery ajax php javascript, cross origin request blocked reason cors header access control allow origin missing, enable CORS php jquery ajax javascript