I'm trying to use this function for infinite scroll:
<script type="text/javascript" charset="utf-8">
(function() {
var page = 1,
loading = false;
function nearBottomOfPage() {
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
}
$(window).scroll(function(){
if (loading) {
return;
}
if(nearBottomOfPage()) {
loading = true;
page++;
$.ajax({
url: '/paginate?page=' + page,
type: 'get',
dataType: 'script',
success: function(data) {
$(".res-list").append(data.responseText);
$(window).sausage('draw');
loading = false;
}
});
}
});
$(window).sausage();
}());
</script>
The problem is it's not appending the data to the unordered list, even though http://localhost:3000/paginate?format=js&page=2 works perfectly.
If I put console.log beneath the line that says: if(nearBottomOfPage()) { it triggers, so i know the function is working fine. Yet if I put the console.log within success: for the ajax function it never triggers.... and still further, If i run the ajax command through console it returns exactly what I need in the 'responseText', with success code 200... so i have no idea why it would nto be triggering a success message in console log if its successfully returning 200 when i do it manually..
heres the controller
def paginate
@resources = Resource.order(:created_at).page(params[:page]).per(20)
respond_to do |format|
format.js
end
end
$.getScript()instead of$.ajax()?'[object Object]'comes fromtoString()ing an object; for example:({}).toString()