我是rails的新手,我不知道如何创建一个无限滚动到我的应用程序。我的javascript代码如下:
<div id = "container1"></div>
<script>
$(document).ready(function() {
$.ajax({
url : "shirts/first",
type : "GET"
});
$("#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"
});
}
});
jQuery(function() {
if ($('.pagination').length) {
$(window).scroll(function() {
var url;
url = $('.pagination .next_page').attr('href');
if (url && $(window).scrollTop() > $(document).height() - $(window).height() - 50) {
$('.pagination').text("Fetching more products...");
return $.getScript(url);
}
});
return $(window).scroll();
}
$.ajax({
url: "shirts/first",
type: "GET"
})
});
});
</script>
这是我的.js.erb文件:
$("#container1").append("<%= escape_javascript(render 'shirts/first')%>");
我是否正确处理了AJAX功能?当我检查firebug时,浏览器正在加载第一页两次,而不是获取其他页面!
我应该对控制器进行任何更改吗?