1

I have an AngularJS site that is pulling in posts from WordPress via the plugin "WP REST API (WP API)". I am testing a site on both dev and staging subdomains, and the WP API works on both. However, when I visit one domain, and then switch over to another domain immediately afterward, then the dynamically-generated Access-Control-Allow-Origin is "stuck" on the previous domain to make the API calls. It's not until I refresh the page, that the response header updates to the current domain making the request. Here is what it says in the Chrome console:

XMLHttpRequest cannot load http://wp.domain.tld/wp-json/pages/couples. The 'Access-Control-Allow-Origin' header has a value 'http://staging.domain.tld' that is not equal to the supplied origin. Origin 'http://dev.domain.tld' is therefore not allowed access.

How do I fix this?

  • What auth are you using? Are you also using SSL? it appears not, but just checking. – brianlmerritt Oct 27 '15 at 21:21
  • have you got an answer? – Murhaf Sousli Dec 3 '15 at 8:43
  • Did you find a solution to your issue? I also have the same issue. – germainelol Mar 4 '16 at 4:51
  • downvoted as it sounds like an angular/browser problem that is not specifically related to wordpress. – Mark Kaplun May 3 '17 at 6:48
  • I'm seeing this also. I've also tried allowing both the initial (preview host) and the live host in allowed origins but still no luck – DJC Oct 11 '17 at 14:48
0

This might be more of an AngularJS question. You can try setting your headers to no-cache. Something like:

var req = {
    headers : {
        "Pragma"        : "no-cache",
        "Expires"       : -1,
        "Cache-Control" : "no-cache"
    }
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.