【发布时间】:2014-03-26 08:03:27
【问题描述】:
当我尝试通过 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 调用:
$(document).ready(function() {
jQuery.ajax({
url: "/footer_info",
type: "GET",
success: function(result){
// ...
},
error: function(e){
console.info("Error-msg: "+e.responseText);
}
});
});
这是控制器方法:
def footer_info
respond_to do |wants|
wants.js
end
结束
这里是呈现部分的 JS 响应:
jQuery("#bottom_wrapper").html("<%= escape_javascript(render(:partial => 'partials/footer/footer')) %>");
所以我希望你能帮助我:(谢谢!
【问题讨论】:
标签: ruby-on-rails ajax http xmlhttprequest cross-domain