Reputation: 155
I know there are lot of queries already posted related to this issue. But I am still not able to resolve the error.
I am getting,
XMLHttpRequest cannot load http://localhost:100/test/test1.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
To resolve I tried following -
--allow-file-access-from-files --disable-web-security
, while launching chrome.exe. (Not working)header('Access-Control-Allow-Origin:*');
in php, after <?php
tag. (Sometimes it works, but not always).$.ajax({crossDomain:true})
I have included. (Not working).Upvotes: 1
Views: 5214
Reputation: 13435
There's a manual:
This presents a variety of options depending your server setup (as well as explain the topic fairly well).
Note that the previous answers are totally correct for PHP... header('Access-Control-Allow-Origin:*');
if you're having problems, remember that you need to send that header before you send any body output to the buffer.
Upvotes: 1
Reputation: 633
Add these three lines:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
Upvotes: 2
Reputation: 955
Simple solution to get this done is you need to add header to server side
header('Access-Control-Allow-Origin:*')
In one of my golang API server,I added below header code to allow CORS
Response.Header().Set("Access-Control-Allow-Origin", "*")
Upvotes: 0