php - multiple callback using jquery .post ajax -


is possible multiple callbacks using jquery .post ajax upload of image php?
sending image server processing thru binary string , hav front end display status when image has uploaded processing icon.

currently using standard .post ideally scenario looking -
jquery:

$.post( 'process.php', { myvar:myvar}, function(data){      if(data=='callback_1'){         // process 1     }else if(data=='callback_2'){         // process 2     }  });  

php:

$myvar = $_post['myvar'];  // after process 1 echo 'callback_1'  // after process 2 echo 'callback_2' 

i set array in php script

$r['callback_one'] = 'complete'; $r['callback_two'] = 'fail';  echo json.encode($r); 

javascript:

r = json.parse(data); if (r.callback_one === 'complete){//do something}; 

of course still sends callbacks @ once, may not after.


the thing can think of if need try , things sequentially use flushing:

how flush output after each `echo` call?

ob_end_flush();  # code needs immediate flushing  ob_start(); 

what may happening client not receive packet server until server has built enough characters send considers packet worth sending.

old answer:

you use ob_implicit_flush tell output buffering turn off buffering while:

ob_implicit_flush(true);  # code needs immediate flushing  ob_implicit_flush(false); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -