Reputation: 449
I have a long ajax call fired in my html template. I'm using jquery, here is the call :
<script>
$(function() {
$.ajax({
type: "POST",
url: "{{ path('my_action') }}",
data: { datas : {
id: '{{ new.id }}'
}}
});
});
</script>
The process behind this call is long and can take several minutes. I don't want to care about it while it's processing, i just want to get the response back, even if i have left the page. So i bind the global ajax event like this :
<script>
$(document).bind("ajaxSuccess", function(event, xhr){
alert('ok');
});
</script>
All is working fine BUT, after the ajax call, i can't do anything. If i want to click a link to go to another page, or if i want to go back, the browser is waiting and nothing happen untill the ajax request is done. Why ? Ajax is asynchronous and should'nt block the browser. Any idea ?
Upvotes: 1
Views: 443
Reputation: 6946
Using Gearman, you can call one synchronous job which gives an initial status and performs some light IO. This job may trigger another asynchronous job and return the job ID to you.
You can then track this asynchronous jobs status: http://php.net/manual/en/gearmanclient.jobstatus.php
For the browser, polling via Ajax might still be necessary to communicate with a PHP script which in turn retrieves Gearman's status (and progress).
Upvotes: 1