will_paginate with jquery:respond_to没有响应js请求

时间:2010-11-28 23:35:28

标签: jquery ruby-on-rails ajax will-paginate

我正在使用jquery以与facebook和twitter相同的方式对我的应用程序进行分页。以下将加载“下一步”结果,但它会加载整个html页面。它似乎没有响应format.js。我在这里做错了什么?

Home Controller

def index
  @products = Product.paginate(:per_page => 2, :page => params[:page])
  respond_to do |format|
    format.html # index.html.erb
    format.js { render :template => '/products_home.html.erb' } # Prodcuts home partial
  end
end

Jquery Javascript to execute AJAX
$(function() {
  $(".pagination a").live("click", function() {
 var pagination = $(this).parent();
    $(".pagination").html("Page is loading...");
 $.get(this.href, function(data) {
   $('#show').append(data);
   alert('Load was performed.');
   pagination.hide();
 });
    return false
  });
});

1 个答案:

答案 0 :(得分:0)

请参阅http://api.jquery.com/jQuery.get/

您需要将“json”的dataType添加到$ .get调用。