Using jQuery/Ajax with PHP to display current progress

后端 未结 3 1886
情话喂你
情话喂你 2021-01-14 17:01

Short and sweet: Looking for a way to call PHP file and display the progress using jQuery and/or Ajax. PHP file upgrade.php?step=1 is called and then the o

3条回答
  •  萌比男神i
    2021-01-14 17:33

    Everyone thank you for your input, with help from some of the guys in the Freenode #jQuery we were able to come up with this which works perfectly:

    var numSteps = 2;
    function loadStepAjax(s) {
        $.ajax('upgrade.php', {
            type: 'GET',
            dataType: 'html',
            data: {
               step: s
            },
            success: function(data) {
                $('#upgradestatus').append(data);
                if (s < numSteps)
                    loadStepAjax(s+1);
                }
         });
    }
    

    You then call the function:

    loadStepAjax(1);
    

    Instead of using a FOR loop we created a function loadStepAjax and then used an IF statement on the callback to determine whether to call the function again.

    It's always something simple isn't it! Thanks for everyone's input though, it is greatly appreciated.

提交回复
热议问题