I have been accessing media images in a Ruby on Rails application via ajax from wordpress 4.2.4.

I am getting following error while accessing the image via ajax.

XMLHttpRequest cannot load http://myblog/wp-content/uploads/2015/11/test.jpeg. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://stage.mysite.com' is therefore not allowed access.

I tried WP-CORS plugin and set * as allowed domains but it doesn't work. I verified that the response doesn't have Access-Control-Allow-Origin header.

I am not wordpress/php guy so would appreciate for simplest possible solution.


Fixed it by adding Header set Access-Control-Allow-Origin "*" in apache2.conf:

<Directory /var/www/>
  Options Indexes FollowSymLinks
  AllowOverride None
  Require all granted
  Header set Access-Control-Allow-Origin "*"
  • 1
    It is possible but only a very small amount of people will be able to do that. You should probably do it in .htaccess or even better at the PHP level. – Mark Kaplun Dec 3 '15 at 8:55

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.