josecebe / twbs-pagination

jQuery pagination plugin (bootstrap powered)
http://josecebe.github.io/twbs-pagination/
Other
1.1k stars 405 forks source link

the difference between ajax init and document ready init? #195

Open vipkouyu opened 4 years ago

vipkouyu commented 4 years ago

I have two pages with different initial ways, pageA is ajax, the other pageB is document.ready The document.ready ways works well, and the ajax ways have two problems:

1、there is nothing happened when you click the next button, but the other three buttons( first previews last) are fine. 2、After initial, I Can't recognize the current page(should be with active class with background color)

How to fix it? code as follows.

HTML `

                </div>`

    ajax initial(pageA)

    function getReply_FirstPage(){
    $.ajax({ type: "post", url: "/postapi/getReply",
    data:{postID:$('#hide-postID').val(),currentPage:1}, success: function(data) {
    $('#div-reply').html(data);

            // alert($('#hide-totalPage').val());
            // alert($('#hide-currentPage').val());
    
            $('#pagination').twbsPagination({
                totalPages: $('#hide-totalPage').val(),
                startPage:$('#hide-currentPage').val(),
                visiblePages: 10,
                initiateStartPageClick:false,                   
                onPageClick: function (event, gPage) {                  
                    alert(gPage);
                }
            });
    
        }
    }); 

    }

    document.ready(pageB,works fine)

           $(document).ready(function(){            
            $('#pagination').twbsPagination({
                totalPages: <%= page.totalPage %>,
                startPage:<%= page.currentPage %>,
                visiblePages: 7,
                initiateStartPageClick:false,
                hideOnlyOnePage:false,              
                onPageClick: function (event, page){
                    var u='/profile/post/'+page;
                    window.location.replace(u); 
                }
            });
        })