雷AJAX分页更新不及时的PAGINATE分页、及时、AJAX、PAGINATE

2023-09-11 01:22:45 作者:玉笛余音向天阙

我使用的是雷宝石实施rails3分页。

I'm implementing pagination in rails3 using the kaminari gem.

我一直在关注从github上这个code https://github.com/amatsuda/kaminari_example/commits/ajax

I've been following this code from github https://github.com/amatsuda/kaminari_example/commits/ajax

不幸的是,以下code

unfortunately, the following code


jQuery('#paginator').html('<%= escape_javascript(paginate(@recipes,:remote=>true).to_s) %>');

似乎并不奏效。

does not seem to be working.

我的javascript什么做什么,用户选择页面

my javascript for what to do what a user selects a page is


  jQuery('a','nav.pagination').click(function(){
         // get the page value from href
          var page = jQuery(this).attr('href').replace('/home/index?page=','');
          jQuery.getJSON('?page='+page, function(data){
                 for (var r in data){
                   results.push(data[r]);
          });
              showResults(results,(page-1)*10);
              jQuery('#paginator').html('<%= escape_javascript(paginate(@recipes,:remote=>true).to_s) %>');
  });

在showResults功能贯穿JSON,并创建了一堆的HTML元素。 一切是伟大的工作,除了分页没有更新,以显示当前页面时的结果重新载入。

the showResults function runs through the JSON and creates a bunch of html elements. Everything is working great, except that the pagination isn't updating to show the current page when the results are reloaded.

我不明白在Firebug的任何错误,我用Rails 3红宝石192。

I don't get any errors in firebug, i'm using Rails 3 with ruby 192.

推荐答案

你确定你有'#paginator元素在你的HTML的分页程序? 我的意思是,以下code返回元素的萤火虫?

Are you sure you have '#paginator' element for the paginator in you HTML? I mean, does the following code return the element on Firebug?

jQuery('#paginator')