Sorry I couldn't find a better title because of my lack of vocabulary.
I have a php script answering to 2 GET parameters : one to start a long process and one to get the process progression.
Something like :
if(isset($_GET['start_generation'])) exit($dossier->generate());
if(isset($_GET['get_status'])) exit($dossier->getStatus());
A button is sending the first request (AJAX POST) and then start a timer that will check the generation status every 2 seconds using another ajax request.
Currently the first request is not ending before the generation is done, so my function to check the status will go directly from 0 to 100.
How can I close the AJAX request before calling generate() ? Can you tell me if output buffering (ob_flush() & friends) is the way to go ?
Thanks
Edit (my ajax code) :
var lastStatus = false;
var checkDossierStatus = function(){
$.get('".$URL."&get_status', function(status){
status = parseInt(status, 10) || 0;
console.log('status '+status);
if(status === lastStatus) return false;
lastStatus = status;
var target;
var activeTitleID = 0;
switch(status){
default:
case 0:
// Show something for status 0...
break;
case 1:
// Show something for status 1... etc...
break;
}
});
};
$('.transmission-start-btn').off('click').on('click', function(e){
e.preventDefault();
$.post('".$URL."', {transmission_action: 'start'}, function(d){
checkDossierStatus();
startStatusCheck();
});
});
checkDossierStatus();before$.post('".$URL."', {transmission_action: 'start'}, function(d){