【问题标题】:Rails 3 Will_Paginate With Ajax Not Updating PartialRails 3 Will_Paginate 与 Ajax 不更新部分
【发布时间】:2012-06-16 22:16:27
【问题描述】:

我正在尝试使用Pagination With Ajax 中指定的 will_paginate gem 将一些 ajax 添加到我的分页中,并且我已经达到了可以在 Firebug 中看到正确的 HTML 响应的程度,但它实际上并没有呈现新代码很奇怪。

这是我的简化代码:

索引操作

def index  
  @videos = Video.paginate :page => params[:page], :per_page =>  per_page
end

index.html.haml

#box_content{:style => "padding: 1em;text-align:center;"}
  = render "video

_video.html.haml

- @videos.each do |video|
    %iframe{:width=>"200", :height=>"150", :src=>link_src(video.link), :frameborder=>"0", :allowfullscreen =>"true"}
%div.pageinfo
    = will_paginate @videos

应用程序.js

$(function () {  
    $('.pagination a').live("click", function () {  
        $.get(this.href, null, null, 'script');  
        return false;  
    });  
});

index.js.erb

$('#box_content').html("<%= escape_javascript(render("video")) %>");

当我点击 will_paginate 链接时,什么都没有发生,如果我查看网络 GET 响应,我会看到以下内容,这确实表明一个新页面:

$('#box_content').html("<iframe allowfullscreen=\'true\' frameborder=\'0\' height=\'150\' src=\'http://www.youtube.com/embed/z52V60aZ7ro\' width=\'200\'><\/iframe>\n<div class=\'pageinfo\'>\n  <div class=\"pagination\"><a class=\"previous_page\" rel=\"prev start\" href=\"/?_=1339623038312&amp;page=1\">&#8592; Previous<\/a> <a rel=\"prev start\" href=\"/?_=1339623038312&amp;page=1\">1<\/a> <em class=\"current\">2<\/em> <a rel=\"next\" href=\"/?_=1339623038312&amp;page=3\">3<\/a> <a href=\"/?_=1339623038312&amp;page=4\">4<\/a> <a class=\"next_page\" rel=\"next\" href=\"/?_=1339623038312&amp;page=3\">Next &#8594;<\/a><\/div>\n<\/div>\n");

【问题讨论】:

    标签: ajax ruby-on-rails-3 response will-paginate


    【解决方案1】:

    事实证明我实际上遇到了 Javascript 错误。我在 Firebug 控制台中没有看到它,因为 Javascript 被呈现为 html 而不是 javascript。然而,在 firebug 控制台中手动执行响应 javascript 让我看到了错误。

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 2012-04-22
      • 2016-09-18
      • 1970-01-01
      • 1970-01-01
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多