Question

I want to make a script that implement jquery to process php script that need a lot of execution time, so I split the process with jquery callback variable to process partially

but i don't know how to implement it. need help!

$("button").click(function(){
    i = 0;
    $("#div1").load("demo.php?i=" + i,function(){
        // when finished do jquery load "demo.php" again with i++ until i = 5
        i++;
    });
});

how to do that?

Was it helpful?

Solution

I would recommend using recursion and a callback function:

$("button").click(function(){
    load(0);
});

function load(i){
    if(i < 6){
        $("#div1").load("demo.php?i=" + i,function(){
            load(++i);
        });
    }
}

OTHER TIPS

var i=0;
function loadQuery(){
    if(i<5)
    {
      $("#div1").load("demo.php?i="+i,function(){
      i++;
      loadQuery();
       });
    }

 }

 $("button").click(function(){loadQuery();}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top