Error:XMLHttpRequest cannot load https://thirdPartyasite/template.html. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I am using Rails application which is consuming Cross orgin data through ajax call.The answers Provided by this question not working.
1)How to set access-control-allow-origin in webrick under rails?
2)https://demisx.github.io/rails-api/2014/02/18/configure-accept-headers-cors.html
3)Allow anything through CORS Policy.
I dont have control over the client app.How to overcome this problem.
I tried This one:
before_filter :set_headers
def set_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
end
Still the same error is coming.
Tried This also:
In gem file added:gem 'rack-cors', :require => 'rack/cors'
In config/application.rb:
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
Still Getting same error.
Work Around For Dev Environment: Install CORS Chrome plugin. But I need Proper Solution