What is the best way of showing progress on an Ajax call?

前端 未结 12 1088
遥遥无期
遥遥无期 2020-11-28 05:17

I have an Ajax call that updates 5,000 records in a database so this takes a lot of time. I have an Ajax \"Loading image\" showing that something is happening, but I am loo

12条回答
  •  一个人的身影
    2020-11-28 05:26

    For showing progress during load, I would modify my backend so that it can do selective loading.

    For example,

    var total_rec = 5000;
    var load_steps = 20;
    var per_load = total_rev / load_steps;
    var loaded = 0; 
    while (loaded < total_rec) {
        www.foobar.com/api.php?start=loaded&end=(loaded+per_load);
        loaded += per_load;
    }
    

    Every time the load is done, update the progress bar.

    An alternative way to modify the backend can be

    www.foobar.com/api.php?start=loaded&count=50
    

提交回复
热议问题