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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf78ef-32076.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf78ef-32076.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?