Rails 3 equivalent for periodically_call_remote

后端 未结 6 1283
刺人心
刺人心 2020-11-29 04:05

Seems like periodically_call_remote is deprecated in Rails 3, any ideas how to achieve the same functionality?

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 04:48

    This is what you need for a periodic ajax call, replace some_path with your own RESTful route:

    <%= javascript_tag do -%>
    $(document).ready(
      function(){
        setInterval(function(){
          $.ajax({
            url: "<%= some_path %>",
            type: "GET",
            dataType: "script"
        });
      }, 60000 );
    });
    <% end -%>
    

    The index.js.erb file would look like this:

    $('#mydiv').html("<%= escape_javascript( render( :partial => 'my_partial' ) ) %>");
    

提交回复
热议问题