will_paginate with jquery: respond_to 不响应 js 请求
我使用 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
});
});
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
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅 http://api.jquery.com/jQuery.get/
您需要添加 dataType将“json”添加到您的 $.get 调用中。
See http://api.jquery.com/jQuery.get/
You need to add dataType of "json" to your $.get call.