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 =开发者_Go百科 $(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.
精彩评论