0

i got the following error, when i'm trying to render a partials via AJAX:

XMLHttpRequest cannot load https://www.domain.de/footer_info. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.domain.de' is therefore not allowed access. 

There seems to be a problem with the protocol. The partial is tried to load via https instead of http. Chrome thinks that is a Cross-Domain-Request (obviously). So my problem is how to fix this error.

Here is my AJAX-Call:

$(document).ready(function() {

jQuery.ajax({
    url: "/footer_info",
    type: "GET",
    success: function(result){
        // ...
    },
    error: function(e){
        console.info("Error-msg: "+e.responseText);
    }
});

});

Here is the Controller-method:

def footer_info
respond_to do |wants|
  wants.js
end

end

And here the JS-response which renders the partial:

jQuery("#bottom_wrapper").html("<%= escape_javascript(render(:partial => 'partials/footer/footer')) %>");

So i hope you can help me :( Thanks!

levitas111
  • 109
  • 2
  • 11

1 Answers1

1

Thanks @Max Williams ! This solved my problem: https://stackoverflow.com/a/9523871/1542555

So here is my modified Controller:

def footer_info
  headers['Access-Control-Allow-Origin'] = "*"
  respond_to do |wants|
    wants.js
  end
end
Community
  • 1
  • 1
levitas111
  • 109
  • 2
  • 11