Reumo
Reumo

Reputation: 31

jquery waypoint add element only the first time

I want to make a waypoint pagination with jquery and ajax request. I added right the first time , but then to add more have to go up and down over the scroll

this is my html

<div id="lista_planes" class="span_of_4">
<div class="col-md-3 span1_of_4">
<div class="col-md-3 span1_of_4">
<div class="col-md-3 span1_of_4">
<div class="col-md-3 span1_of_4">
</div>

this is my Js

var pagina = 2;
    var hayMasPlanes = true;
    var opts = {
        offset: '100%'
    };
    $('#verMas').waypoint({
        handler: function(direction){
            if(direction == 'down'){
             $.get('<?php echo Router::url(array('action' => 'ajaxPlanes')) ?>/' + pagina, '',
                function (dato) {
                    
                    if(dato == ''){
                        $('#verMas').hide();
                    }
                    pagina++;
                    $('#lista_planes').append(dato);
                    
               }
               );
        }},
        offset: '50%'
    });

Upvotes: 1

Views: 511

Answers (1)

Reumo
Reumo

Reputation: 31

Solveeed. add Waypoint.refreshAll(); in ajax request

$('#verMas').waypoint({
        handler: function(direction){
            if(direction == 'down'){
             $.get('<?php echo Router::url(array('action' => 'ajaxPlanes')) ?>/' + pagina, '',
                function (dato) {
                    
                    if(dato == ''){
                        $('#verMas').hide();
                    }
                    pagina++;
                    $('#lista_planes').append(dato);
                    Waypoint.refreshAll();
               }
               );
        }},
        offset: '50%'
    });

Upvotes: 1

Related Questions