Saturday, 7 September 2013

How to set a loop with a timer that makes ajax requests until a response is reached

How to set a loop with a timer that makes ajax requests until a response
is reached

I have the following jQuery:
$.ajax('/contacts_imported', {
dataType : 'json',
data : {
email : cfg.email
},
success : function(data) {
if (data[0].processed) {
alert('Processed is TRUE!');
} else {
alert('Not yet Processed');
}
}
});
What I'm trying to do is, have this ajax request run every second until
processed is equal to True. Once True, run a separate functions and kill
the timer/loop.
Suggestions on host to best handle this in an elegant way?
Thanks

No comments:

Post a Comment