Ajax paging page jump failed

1. According to the tutorials on the Internet, I wrote a paging query, but after the query results, the value of the next page of the page is always 2, and the last page is 0. There is no response when clicked.

</span></a></div>" + 
                    "</div>" + 
                    "</div>";
                }
                $("-sharpdata").html(str);            
            
            

            }
        })
}  

//
function countpage(){
    var countpage = 0;
    var key = $("-sharpkey").val();
    var time = $("-sharptime").val();
    $.ajax({
        
        url:"taobao_countpage.php",
        data:{key:key,time:time},
        type:"POST",
        dataType:"TEXT",
        success:function(data){
            countpage = Math.ceil(data/display);
            console.log(countpage);
            
        }
    });
    return countpage;
}



//            
function Loadlist() {
    console.log(page);
    if(page > countpage()) {
        page = countpage();
    }
    if(page < 1) {
        page = 1;
    }

    pageBar = "";

    //
    if(page != 1){
        pageBar += "<a href="javascript:Load(1)"></a>";
        pageBar += "<a href="javascript:Load("+(page-1)+")"></a>";
    }
      //
    if(page != countpage()){
        pageBar += "<a href="javascript:Load("+(parseInt(page)+1)+")"></a>";
        pageBar += "<a href="javascript:Load("+countpage()+")"></a>";
    }
    
    $("-sharpfenye").html(pageBar);
}
Mar.16,2021
The ajax in

countpage is an asynchronous request. The page is loaded for the first time and you haven't got the data yet. When you use the countpage () method, make sure you get the data at this time.

Menu