Do loading status processing according to the data size obtained by ajax.

for example, I have a request on the page, which may have a large amount of data or very small. I want to have a loading state when the amount of data is large, and if the amount of data is small, there is no loading state. Load
directly because in actual development, if we do not make this judgment, when the amount of data is small, the loading will end instantly and flash on the page, which is very bad for the user experience.

at present, the method we adopt is one-size-fits-all. Each load has a minimum Loading,loading time of 1 second. If the amount of data is large, the loading time will be extended.

what should I do if I want to do loading processing based on the time the data is returned?

Jul.27,2021

you can add a delay mechanism inside the loading to set a minimum time to start the loading. The logic goes like this:

function loadingFx(delay){
    setTimeout(function(){
        loadingAnimate();
    },delay||0);
}

start a timer before the request, and display loading in the timer, depending on your specific situation, while retaining the application of the timer. When it is over, clear the timer


No matter how you set the threshold, you may only see a fleeting situation, or wait a long time (because the content download is not only related to file size, but also related to the network environment)
so I recommend uniformly setting loading
in order to express fast, you can set a minimum loading display time, even if the download is completed, you have to show loading for a while.


loading
:
.loading
.let number=0;
.let interval=setInterval((){
    numberPP
},1000)//1000
.
ajax.post(
    ){(res)=>{
        //
        //number
        if(number>=2){//220001000
            //loading
        }else{
            //22000loadingloading
            setTimeout(()=>{
                // loading
            },1000)
            // 
            clearInterval(interval)
        }
    }}
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-1e9d7a2-1962.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-1e9d7a2-1962.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?