简体   繁体   中英

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. The following will load "next" results but it loads the whole html page. It seems it is not responding to the 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/

You need to add dataType of "json" to your $.get call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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