使用pjax_rails實現局部頁面刷新

繼續使用上篇博客中用到的項目---引入pjax ,把application.js中引入的turbolinks刪掉
   Gemfile
gem 'pjax_rails'
   app/assets/javascripts/application.js
 //= require jquery.pjax
  // app/assets/javascripts/application.js
  $(function() {
    $(document).pjax('a:not([data-remote]):not([data-behavior]):not([data-skip-pjax])', '[data-pjax-container]')
  })
   layouts/application.html.erb
  <body>
    我是一隻小小小小鳥  <%= Time.now %>
    <div data-pjax-container>
      <%= yield %>
    </div>
  </body
   index.html.erb
  <div data-pjax-container>
    <!-- PJAX updates will go here -->
    <%= content_tag :h3, 'My site' %>    <br>
    <%= link_to 'test_pjax_person_1', '/people/1' %>      
    <!-- The following link will not be pjax'd -->
    <%= link_to 'test_skip_pjax_person_1', '/people/2', 'data-skip-pjax' => true %>    <br>
  </div>

可以看到使用後的效果,鏈接

使用pjax後的請求


未使用pjax的請求



項目下載                  liutaiquan

發佈了37 篇原創文章 · 獲贊 7 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章