通过json查询/显示变量的值,间隔10ms


Check/Display value of variable via json in interval of 10ms

我正在尝试使用jquery旋钮和php制作一个进度圈。Jquery旋钮应该通过ajax/json从计算迭代的php中获取变量的值有了这个php脚本,我得到的总迭代的百分比已经完成。这个想法是用jquery,从这里得到的数字json_encode($percentage)每20毫秒。它看起来像一个进度圆并根据从json_encode($percentage)中得到的数字填充颜色请帮助我,我是一个新手在jquery,但我知道一点php。

PHP

$urls1 is an array;
$counter = 0;
$total = count($urls1); 
foreach ($urls1 as $urls) {
  $counter++;
  $percentage = ($counter/$total) * 100;
  echo json_encode($percentage);
  // some morethings to do
}
现在Jquery

var jQuery_1_11_0 = $.noConflict(true);
$(function () {
    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('');
            $("#progressbar").knob({
                'draw': function () {
                    /*$.ajax({
                        url: 'multipr-process.html', // it's acually php, but i am using htaccess code, it works fine tested on other scripts.
                        type: 'GET',
                        data: data,
                        dataType: 'json',
                        success: function (result) {
                            //console.log(result['percentage']);
            var currentpercentage = result['percentage'];
            I want the result to get it every 20 ms and I believe that I need to place it in a variable, so
            I can add it beyond....
                        }
                    });*/
        //// if I enable this, ajax script above brokes and can't check in the console because it's reloading page.
                    $(this.i).val(currentpercentage + '%');
                }
            });
            $.ajax({
                type: 'post',
                url: 'lib/multipr-process.html',
                data: $('#check').serialize(),
                success: function (data) {
                    $("#result").html(data); // apple
                    $("#progressbar").knob().hide();
                }
            });
            e.preventDefault();
        } // ending the else
    });
});

不确定您在这里的目的是什么,也不确定您的$urls1是如何组成的,但这是尽可能想到的,至少是灵感:

PHP简单返回:

echo json_encode($urls1);

AJAX成功函数:

success: function (data) {
  $("#progressbar").knob().hide();
  var total = data.length;
  var counter = 0;        
  var dt = setInterval(function() {
    if ( !data[counter] ) { clearInterval(dt); }
    else { $("#result").html((counter/total) * 100); }
    //else { console.log(data[counter]); }
    counter++;
  }, 2000); // slowed down, if works set to 20
 }