javascript - Check/Display value of variable via json in interval of 10ms -
i trying make progress circle using jquery knob , php. jquery knob should value via ajax/json of variable php counting iterations php script getting percentage of total iteration had been done. idea jquery, number here json_encode($percentage) every 20 ms. appears progress circle , fullfill color based on number gets json_encode($percentage) please me noob in jquery know bit of php.
php
$urls1 array; $counter = 0; $total = count($urls1); foreach ($urls1 $urls) { $counter++; $percentage = ($counter/$total) * 100; echo json_encode($percentage); // morethings }
now 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 new line -max 100 domains-') { validaterror.text('please enter domain names in text area'); e.preventdefault(); } else { validaterror.text(''); $("#progressbar").knob({ 'draw': function () { /*$.ajax({ url: 'multipr-process.html', // it's acually php, using htaccess code, works fine tested on other scripts. type: 'get', data: data, datatype: 'json', success: function (result) { //console.log(result['percentage']); var currentpercentage = result['percentage']; want result every 20 ms , believe need place in variable, can add beyond.... } });*/ //// if enable this, ajax script above brokes , can't check in 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 else }); });
not purpose here or how $urls1 composed, comes mind as possibility, @ least inspiration:
php returns:
echo json_encode($urls1);
ajax success function:
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 20 }
Comments
Post a Comment