Rails的使用Ajax时返回一些重复的记录Rails、Ajax

由网友(我不姓福)分享简介:所以,我有一个应用程序,有一些影片剪辑,用户可以搜索特定主题等等...我使用Ajax来处理分页,以便用户可以进行搜索查询,滚动查看更多结果(类似推特)。 So, I have an app that has several movie clips and users can search for specific t...

所以,我有一个应用程序,有一些影片剪辑,用户可以搜索特定主题等等...我使用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

阅读全文

相关推荐

最新文章