• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 530
  • Last Modified:

No 'Access-Control-Allow-Origin' header is present...

When attempting to execute the following javascript:

var url = 'http://www.mywebsite.com/wp-content/private/data.json';
try {
      $.getJSON(url, function(result){
} catch(e) {

Open in new window

I get this error: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access.

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";

Open in new window

What am I doing wrong?  Do I need to set something on the website?  If so what?
Thank you very much
Michael David
Michael David
1 Solution
David Johnson, CD, MVPOwnerCommented:
You need to add the header:
Access-Control-Allow-Origin *
Access-Control-Allow-Origin http://www.foo.com

Otherwise this is known as cross site scripting which is by default denied.  Since you are also not using a 'domain' in your instance you also have to
Julian HansenCommented:
Here are the headers I am setting:
Those are the headers sent from the client.
You need to add the headers, Dave has in his post, to your server response.
you need to add a plugin like this in your wordpess site (mywebsite.com) znf configure it :

/!\ you MUST limit site doing request to your wordpress site
Michael DavidAuthor Commented:
Thank you very much for your time and expertise.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now