Rails的使用Ajax时返回一些重复的记录 [英] Rails returning several duplicate records when using Ajax

查看:126
本文介绍了Rails的使用Ajax时返回一些重复的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个应用程序,有一些影片剪辑,用户可以搜索特定主题等等...我使用Ajax来处理分页,以便用户可以进行搜索查询,滚动查看更多结果(类似推特)。

So, I have an app that has several movie clips and users can search for specific topics etc... I'm using Ajax to handle pagination so that users can make a search query and scroll to view more results (similar to twitter).

问题是,当IE浏览器滑稽一堆记录用户的搜索将拿出,并为用户向下滚动阿贾克斯将加载的记录与新记录很长的重复。

The issue is when a user searches for i.e. "Funny" a bunch of records will come up and as the user scrolls down Ajax will load duplicates of the records a long with new records.

这里的code:

if $('.pagination').length
  $(window).scroll ->
    url = $('.pagination .next_page').attr('href')
    if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
      $('.loader').removeClass('hidden')
      $.getScript(url)
  $(window).scroll()

下面是一个屏幕截图

Here's an screenshot

我怎样才能起价在这种情况下重复记录p $ pvent轨道?我试过uniq的和一些其他方法都无济于事。

How can I prevent rails from duplicating records in this case? I've tried uniq and several other methods to no avail.

谢谢!

更新这里的一些额外的code可能有助于调试这样的:

Update here's some additional code that may be helpful in debugging this:

https://gist.github.com/pblogs/e202ee1f03339ba977ec

推荐答案

确认要更换的内容,而不是追加另一组的结果,以现有的在你的.js.erb

Make sure you are replacing contents instead of appending another set of results to existing ones in your .js.erb

这篇关于Rails的使用Ajax时返回一些重复的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆