0

I have an ajax call which is used to perform a task and correspondingly update a table with the progress status.Now i have another ajax call to fetch the status from the table to show the task progress status to the user.The second call gets called repeatedly for every 2 seconds until the task is complete.But i could not show the task progress status to the user as the second ajax call keeps on loading till the response comes for the first ajax call.

I found a similar question in stackoverflow in the following link and it was suggested that it might be due to session lock and that using session_write_close() might work.I tried it and found no success. Prevent jQuery AJAX call from waiting for previous call to complete

Is there a way to get the response for the second ajax call even while the first ajax call is still processing?

Community
  • 1
  • 1

1 Answers1

0

You can controller your Ajax functions flow using deferring concept of jQuery like

var defered = jQuery.Deferred();

function your_function(){
 //do something!
 defered.reslove()
 return defered.promise
} 
your_function.then(function(){
 //this will not run till your_function is done 
})

learn more at https://api.jquery.com/jQuery.Deferred/

Peter Wilson
  • 4,150
  • 3
  • 35
  • 62
  • But i need the second ajax call to be called for every 2s to get the table update..can this be done with deferred? – Geethanjali Mar 09 '16 at 07:31