开发者

Render js.erb for XHR request

开发者 https://www.devze.com 2023-02-02 11:02 出处:网络
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 a

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

精彩评论

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