progress bar in php & jquery
Question
i have a PHP process who send X mails After each mail send, i add a line on a database for tell that a mail is send.
So, i wan't to create a progress bar for tell to the user that X mails are sended on Y ( Y = total)
I have two jquery function like that :
function mail_send()
{
$('.loading').css('display','block');
$.ajax({
'url': '/an/url/',
'data': {
someParam: param
},
'beforeSend':function()
{
$('#loadingBg').append('<span id="count"></span>');
setTimeout(function () {
mail_updateProgress(id);
}, 500);
}
,
'success': function (data,textStatus)
{
(....)
}
});
}
function mail_updateProgress(id) {
$.ajax({
'url': '/an/url/',
'data': {
someParam: param
},
'success': function (data) {
var res = $.parseJSON(data);
$('#count').html(res.nbSended + '/' + res.total);
}
});
}
The problem is that i can't send more than 15 mail right now and i'll not create XXX mail adresses for test it, but the updateProgress() function just success one time and it's happen in the same time of the mail_send() function.
Is there an error ?
thanks
EDIT : Ok, so setInterval is good, but i have a second problem, Is there a queue for the $.ajax ? I'm loggin 3 things : first : When the process is enter on the updateProgress function second : when the updateProgress ajax is successed third : When the mail_send() ajax is successed
the order of the log is
fisrt (X times ) Third (1time) second(X times)
so, my progress bar never progress, just make 0% => 100% when the send function is ended
any idea to process the progress function while the send function ? is it possible to delegate ?
Solution
You're using setTimeout If you want intervalled checking use: setInterval.