Note that there are some explanatory texts on larger screens.

plurals
  1. POHTTP Streaming with Apache, Perl, and jQuery?
    text
    copied!<p>I'm trying to prepare a proof of concept for a page that will take a file that a user chooses, process it, and return it, all the while reporting on the status of the process. I thought the best solution for this may be HTTP streaming, however I can only get it working in Firefox (not Chrome or IE8.)</p> <h2>load.js</h2> <pre><code>$(function() { var xhr = $.ajax({ url: '/nph-handleRequest.cgi' ,type: 'get' }); collectPartial(xhr,''); }); var collectPartial = function (xhr,lastContent) { alert(xhr.readyState); if (xhr.readyState == 3 &amp;&amp; lastContent != xhr.responseText) { lastContent = xhr.responseText; alert(xhr.responseText); } if (xhr.readyState &lt; 4) { setTimeout(function() {collectPartial(xhr,lastContent)}, 1000); } } </code></pre> <h2>nph-handleRequest.cgi</h2> <pre><code>#!/usr/bin/perl $|=1; print "$ENV{SERVER_PROTOCOL} 206 Partial Content\n"; print "Server: $ENV{SERVER_SOFTWARE}\n"; print "Content-type: text/plain\n\n"; for ($count = 1; $count &lt; 5; $count++) { print time(); print "\n"; sleep(2); } </code></pre> <p>In Firefox, the alert(xhr.readyState) keeps displaying a 3, as I would expect. In Chrome, though? 1. In IE it's 2. Neither allow me to access responseText either.</p> <p>Any suggestions as to what I'm doing wrong would be greatly appreciated.</p> <h2>Edit 1</h2> <p>It's actually MiniServ, not Apache. The server doesn't appear to be the issue though, as it works in one browser, and not another.</p> <h2>Edit 2</h2> <p>After discovering CGI::Push, I tried using that, despite warnings that it doesn't work in IE. Oddly, it DID work in IE8 (not perfectly), but still not in Chrome.</p> <pre><code>#!/usr/bin/perl $|=1; use CGI::Push qw(:standard); do_push(-next_page=&gt;\&amp;display_time,-delay=&gt;2); sub display_time { my($q,$counter) = @_; return undef if $counter &gt; 5; return time()," "x256, "\n"; } </code></pre>
 

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