开发者

Render js.erb for XHR request

I want to set rails to render开发者_开发知识库 .js.erb files by default for xhr requests.


If you are using jQuery then update your rails.js to the latest from here https://github.com/rails/jquery-ujs and set the default request header for ajax calls with this:

$(function() {
    jQuery.ajaxSetup({
        beforeSend: function(xhr) {
            xhr.setRequestHeader("Accept", "text/javascript");
        }
    });
});

Here is a very recent commit for reference: https://github.com/rails/jquery-ujs/commit/fbbefa0773d791d3a67b7a3bb971c10ca750131b

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜