我有一个具有搜索功能的应用程序。索引页面显示数据库中的所有项目,另外,当我搜索产品时,它也可以使用AJAX进行工作。那么,如何在分页中添加AJAX功能? 我正在使用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:
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.