Symfony ajax progress bar

I have an ajax controller that loops through a loop. I would like to update the progress bar after this controller progress. Basically, I just need to print $('.bar').css('width', $percent . '%') .
But all these outputs are simply accumulated and sent after the function is completed.

How to update the panel after each output?
I already tried flush() and ob_flush() .

Does Symfony use other buffers?

EDIT: part of the controller that runs javascript

 $total = count($results); foreach ($results as $result) { $count++; echo '<script>$(\'.bar\').css(\'width\', \'' . (int)($count / $total * 100) . '%\');</script>'; } 
+6
source share
1 answer

You should use session-write-close () in your long php action.

JS:

 var isInProgress = false; function veryLongImport() { isInProgress = true; checkfx(); $.ajax({ type: "GET", url: /myverylongueactionPath , async : true, cache: false, dataType:'html', success: function(data){}, error: function(){ }, complete: function(){ isInProgress = false; } }); } function checkfx() { if( isInProgress != false ) { $.ajax({ type: "GET", url: /mycheckpath , async : true, cache: false, dataType:'html', success: function(data){ makeYourProgressBarGrowHere(); }, error: function(){ }, complete: function(){ checkfx(); } }); } else { } } 

PHP controller:

 public function myVeryLongAction($id) { session_write_close(); ... code ... } public function myCheckAction() { ...code... } 
+3
source

Source: https://habr.com/ru/post/959040/


All Articles