AJAX页面重新加载

时间:2014-01-28 11:55:53

标签: javascript ruby-on-rails ajax pagination kaminari

我有一个具有搜索功能的应用。索引页面显示数据库中的所有项目。此外,当我搜索我的产品时,它使用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",
             });    
            }
          });
          });

1 个答案:

答案 0 :(得分:0)

只需添加到您的分页链接remote: true或使用javascript处理它,然后在您的控制器中:

if request.xhr?
  render json: @products # ajax request
else
  render layout: true # standard layout
end

您必须在自己的javascript中抓取'ajax:success'并附加已收到的产品。