[英]AJAX page reloading
I have a app with search functionality. 我有一个具有搜索功能的应用程序。 The index page displays all the items in the database.
索引页面显示数据库中的所有项目。 Also when I search my products it works using AJAX.
另外,当我搜索我的产品时,它也可以使用AJAX进行工作。 How to add AJAX functionality to my pagination?
如何在我的分页中添加AJAX功能? I'm using Kaminari for my pagination.
我正在使用Kaminari进行分页。
$(function() {
$( "#name" ).autocomplete({
source: "shirts/autocomplete",
autoFocus: false,
minLength: 1,
select: function(event,ui){
document.getElementById("name").value = ui.item.value;
$.ajax({
url:"shirts/show?name="+ui.item.value,
type:"GET",
});
}
});
});
Simply add to your pagination link remote: true
or handle it with javascript and then in your controller: 只需将
remote: true
添加到您的分页链接remote: true
或使用javascript处理它,然后在您的控制器中:
if request.xhr?
render json: @products # ajax request
else
render layout: true # standard layout
end
You will have to catch 'ajax:success'
in your javascript and append the recieved products. 您将必须在JavaScript中捕获
'ajax:success'
并附加收到的产品。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.