简体   繁体   English

用jQuery will_paginate:response_to不响应js请求

[英]will_paginate with jquery: respond_to not responding to js request

I am using jquery to paginate my application in the same way facebook and twitter do so. 我使用jquery以与facebook和twitter相同的方式对应用程序进行分页。 The following will load "next" results but it loads the whole html page. 以下将加载“下一个”结果,但它将加载整个html页面。 It seems it is not responding to the format.js. 似乎它没有响应format.js。 What am I doing wrong here? 我在这里做错了什么?

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
  });
});

See http://api.jquery.com/jQuery.get/ 参见http://api.jquery.com/jQuery.get/

You need to add dataType of "json" to your $.get call. 您需要在$ .get调用中添加“ json”的dataType。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM