下面是我的代码:
$(document).ready(function(){
$("#pbo").hide();
$('.pie_progress').asPieProgress({
namespace: 'pie_progress',
size: 100,
barsize: '4'
});
$("#getit").click(function(){
$.post("process.php",
{
yurl: $("#yurl").val()
},
function(data,status){
if(data > 0 ) {
$('#yurl').hide();
$('#getit').hide();
$("#pbo").show();
$('h1').hide();
$('.pie_progress').asPieProgress('start');
$('.pie_progress').asPieProgress('go',data);
} else {
$('#yurl').show();
$('#getit').show();
$("#pbo").hide();
}
});
});
});
当我点击我的#getit
按钮时,它执行process.php
并获得返回的数据,这些数据依次传递给$('.pie_progress').asPieProgress('go',data);
。我的进度条会用这些数据更新,但这似乎只会发生一次。是否有办法继续使POST
请求,直到数据值为100?
注意:在process.php中,我有一个php exec,它每秒都会返回进度。
将ajax调用放在函数中(例如:processTo100)并每次都调用它怎么样?
像这样:
$(document).ready(function(){
$("#pbo").hide();
$('.pie_progress').asPieProgress({
namespace: 'pie_progress',
size: 100,
barsize: '4'
});
$("#getit").click(function(){
processTo100();
});
function processTo100() {
$.post("process.php",
{
yurl: $("#yurl").val()
},
function(data,status) {
if(data > 0 ) {
$('#yurl').hide();
$('#getit').hide();
$("#pbo").show();
$('h1').hide();
$('.pie_progress').asPieProgress('start');
$('.pie_progress').asPieProgress('go',data);
if( parseInt(data) <= 100) {
processTo100();
}
} else {
$('#yurl').show();
$('#getit').show();
$("#pbo").hide();
}
});
}
});