Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent ajax progress code from aborting prematurely
    primarykey
    data
    text
    <p>I am using index.php</p> <pre><code>&lt;script type="text/javascript"&gt; $(function(){ $("#progressbar").progressbar({ value: 0 }); function load() { $.ajax({ url: './ajax.php?status='+$( "#progressbar" ).progressbar( "value" ), success: function(data) { ajax = eval('(' + data + ')'); if(ajax!=false) { $("#progressbar").progressbar({ value: ajax.status }); $("#message").html( ajax.message ); if(ajax.status!=100) { load(); } } } }); } load(); }); &lt;/script&gt; &lt;div id="message"&gt;&lt;/div&gt; </code></pre> <p>for a live ajax-based progress information. This works with ajax.php:</p> <pre><code>&lt;?php $php_array['status'] = rand(0,99); if($php_array['status']&gt;100) { $php_array['status'] = 100; } if($php_array['status'] != 100) { $php_array['message'] = 'Aktueller Status &lt;b&gt;'.$php_array['status'].'%&lt;/b&gt; von 100%, Differenz: '.(100-$php_array['status']); } else { $php_array['message'] = 'Juhu endlich geschafft!'; } // Ausgabe des PHP Arrays als JSON Objekt echo json_encode($php_array); ?&gt; </code></pre> <p>which shows a random number between 0 and 99 in index.php, so it works.</p> <p>I modified ajax.php to</p> <pre><code>&lt;?php //modified - start $zahl = 0; $menge = 0; if ($handle = opendir('folder')) { while (false !== ($entry = readdir($handle))) { if (strpos($entry,$_GET['session_id']) !== false) { if (strpos($entry,'result') !== false) { } else { $zahl += (int)file_get_contents('folder/'.$entry); $menge++; } } } closedir($handle); } if((int)($zahl/$menge) != 0.0) { $php_array['status'] = (int)($zahl/$menge); } else { $php_array['status'] = 0; } //modified - end if($php_array['status']&gt;100) { $php_array['status'] = 100; } if($php_array['status'] != 100) { $php_array['message'] = 'Aktueller Status &lt;b&gt;'.$php_array['status'].'%&lt;/b&gt; von 100%, Differenz: '.(100-$php_array['status']); } else { $php_array['message'] = 'Juhu endlich geschafft! &lt;img src="http://d4nza.de/blog/wp-includes/images/smilies/icon_wink.gif" alt=";)" class="wp-smiley"&gt; '; } echo json_encode($php_array); ?&gt; </code></pre> <p>The opendir-part iterates through all output-text-files, which contain only a number between 0 and 100. Goal is to find the average progress. Then in</p> <pre><code>(int)($zahl/$menge) </code></pre> <p>it is being converted to an integer and forwarded via json to the index.php.</p> <p>This works sometimes. That means, on index.php sometimes I see the progress, sometimes I don't. </p> <p>How can I make the code in the index.php make it wait for the ajax.php to respond and not (presumably) abort prematurely?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload