Michael David
asked on
No 'Access-Control-Allow-Origin' header is present...
When attempting to execute the following javascript:
I get this error: No 'Access-Control-Allow-Orig in' header is present on the requested resource. Origin 'http://127.0.0.1:8080' is therefore not allowed access.
Here are the headers I am setting:
What am I doing wrong? Do I need to set something on the website? If so what?
Thank you very much
var url = 'http://www.mywebsite.com/wp-content/private/data.json';
try {
$.getJSON(url, function(result){
console.log(result);
});
} catch(e) {
console.log(e);
}
I get this error: No 'Access-Control-Allow-Orig
Here are the headers I am setting:
angular.module.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.headers.common = {'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Method': 'GET, POST'};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};
$httpProvider.defaults.useXDomain = true;
$httpProvider.defaults.withCredentials = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
$httpProvider.defaults.headers.common["Accept"] = "application/json";
$httpProvider.defaults.headers.common["Content-Type"] = "application/json";
}
]
)
What am I doing wrong? Do I need to set something on the website? If so what?
Thank you very much
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you need to add a plugin like this in your wordpess site (mywebsite.com) znf configure it :
https://github.com/jacopotarantino/WordPress-Cross-Domain-Plugin
/!\ you MUST limit site doing request to your wordpress site
https://github.com/jacopotarantino/WordPress-Cross-Domain-Plugin
/!\ you MUST limit site doing request to your wordpress site
ASKER
Thank you very much for your time and expertise.
You need to add the headers, Dave has in his post, to your server response.