当我试图通过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. 协议似乎有问题。尝试通过https而不是http加载部分。Chrome认为这是一个跨域请求(显然)。所以我的问题是如何修复这个错误。
下面是我的AJAX-Call:
$(document).ready(function() {
jQuery.ajax({
url: "/footer_info",
type: "GET",
success: function(result){
// ...
},
error: function(e){
console.info("Error-msg: "+e.responseText);
}
});});
下面是Controller-method:
def footer_info
respond_to do |wants|
wants.js
end结束
这里是呈现部分的JS-response:
jQuery("#bottom_wrapper").html("<%= escape_javascript(render(:partial => 'partials/footer/footer')) %>");所以我希望你能帮助我:(谢谢!
发布于 2014-02-24 23:44:42
谢谢@Max Williams!这解决了我的问题:https://stackoverflow.com/a/9523871/1542555
下面是我修改后的控制器:
def footer_info
headers['Access-Control-Allow-Origin'] = "*"
respond_to do |wants|
wants.js
end
endhttps://stackoverflow.com/questions/21991490
复制相似问题