试图从php获取json的实时百分比

I am trying to update on screen without refresh the current percentage that is updated into a database when the user checks something but failed to accomplish this. Problem is that in the console I get the error TypeError: a is undefined ..."resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b and the GET request is repeated infinite. Within the get request, the response is: {"percentage":null}. An additional problem is that the GET request seams to load complete (like getting the final response) only when the php script finishes. I checked the database and every time I refresh the database dynamically I can see the percentage updating. So it's not a problem from the PHP or SQL, may be a problem from getter.php (file that is printing the result) and the json script. Please help me on this issue I checked the entire day + yesterday on how to echo value from database live and tried lots of examples but did not understood complete how to do it (this is mostly related to jquery knob, want to implement it there after success). Your help is much appreciated.

Jquery:

jQuery_1_11_0('#check').on('submit', function (e) {
    done();

    function done() {
        setTimeout(function () {
            updates();
            done();
        }, 1000);
    }

    function updates() {
        $.getJSON("lib/getter.php", function (data) {
            $("#progressbar").empty();
            $.each(data.result, function () {
                percentage = this['percentage'];
                if (percentage = null) {
                    percentage = 100;
                    $("#progressbar").html(percentage);
                }
            });
        });
    }
});

process.php

$urlsarray = array('google.com', 'yahoo.com', 'bing.com'); 
// this is a dynamic array created by the user, I am giving just a simple example
$counter = 0;
$total = count($urls1);
$session_id = rand(100000000000000, 999999999999999);
$db->query("INSERT INTO sessions (session_id, percentage) VALUES ('$session_id', '$counter')");
foreach ($urlsarray as $urls) {
    doing some things
    $counter++;
    $percentage = ($counter/$total) * 100;
    $db->query("UPDATE sessions SET percentage = '$percentage' WHERE session_id = '$session_id'");       
}
$db->query("DELETE FROM sessions WHERE session_id = '$session_id'");
$percentage = 100;

getter.php

include("process.php");
global $session_id;
$readpercentage = $db->query("SELECT percentage FROM sessions WHERE session_id = '$session_id'");
$percentage = $readpercentage->fetch_assoc();
echo json_encode(array('percentage' => $percentage));
ob_flush();
flush(); 

EDIT 2 UPDATE

function updates() {
    $.getJSON("lib/getter.html", function (data) {
        $("#progressbar").empty();
           $("#progressbar").html(data.percentage);
    });
}

EDIT 3

var myInterval = setInterval(function(){ updates(); }, 1000);
    function updates() {
        $.getJSON("lib/getter.html", function (data) {
            //$("#progressbar").empty();
            console.log(data);
            $("#progressbar").html(data.percentage);
            if(data.percentage >= 100){
                clearInterval(myInterval);
            }
        });
    }

EDIT 4. changed getter.php

include("process.php");
//global $session_id;
//echo $session_id;
$readpercentage = $db->query("SELECT percentage FROM sessions WHERE session_id = '$session_id'");
$percentage = $readpercentage->fetch_assoc();
$percentage = (int) $percentage['percentage'];
if ($percentage = 100) {
    $percentage = 100;
}
echo json_encode(array('percentage' => $percentage));
ob_flush();
flush(); 

and the js script

var jQuery_1_11_0 = $.noConflict(true);
jQuery_1_11_0('#check').on('submit', function (e) {

var myInterval = setInterval(function(){ updates(); }, 1000);
    function updates() {
        $.getJSON("lib/getter.html", function (data) {
            var percentage = data.percentage;
            $("#progressbar").html(percentage).show();
            if(percentage >= 100 || typeof percentage !== 'undefined'){
                clearInterval(myInterval);
            }
        });
    }
});
// second script is for posting the result
jQuery_1_11_0('#check').on('submit', function (e) {
    var validatef = $("#url").val();
    var validaterror = $('#errorvalidate');
    if (validatef == 'Enter Domains Separated By New Line -MAX 100 DOMAINS-') {
        validaterror.text('Please enter domain names in the text area');
        e.preventDefault();
    } else {
        validaterror.text('');
        $.ajax({
            type: 'post',
            url: 'lib/process.php',
            data: $('#check').serialize(),
            success: function (data) {
                $("#result").html(data); // apple
                // $("#progressbar").knob().hide();
            }
        });

        e.preventDefault();

    } // ending the else
});

I cant help but wonder:

done();

function done() {
    setTimeout(function () {
        updates();
        done();
    }, 1000);
}

How does this recursion stops? Because to me it seems like this timeout will keep on firing eternally. You really need a timeInterval here, set it to a variable, and clear the interval when 100% has been reached.

Maybe replace the above with:

var myInterval = setInterval(function(){
    updates();
}, 1000);

then, on the updates function

if(percentage >= 100){
    clearInterval(myInterval);
}

By the way, doing:

if(percentage = null){
    ...
}

Did you mean to compare using = instead of == ? If you want to verify that percentage is set and is a valid number, it would probably be a good idea to do:

if(typeof percentage !== 'undefined' && !isNaN(parseFloat(percentage)){
    ...
}

Look at what you're sending back to your JS code from PHP:

echo json_encode(array('percentage' => $percentage));

Literally that'll be

{"percentage":42}

In your JS code, you then have:

    $.getJSON("lib/getter.php", function (data) {
                                          ^^^^---the data coming back from PHP
        ....
        $.each(data.result, function () {
                    ^^^^^^---since when did you put a "result" key into your array?

For this JS code to work, you'd have to be doing

echo json_encode(array('result' => $percentage));
                        ^^^^^^---note the new key.

And note that since you're sending back a SINGLE object in the JSON, with a single key:value pair, there is literally no point in using your inner $.each() loop. You could just as well have

$("#progressbar").html(data.percentage);