views:

94

answers:

0

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.)

load.js

$(function() {
        var xhr = $.ajax({
                url: '/nph-handleRequest.cgi'
                ,type: 'get'
        });

        collectPartial(xhr,'');
});

var collectPartial = function (xhr,lastContent) {
        alert(xhr.readyState);
        if (xhr.readyState == 3 && lastContent != xhr.responseText) {
                lastContent = xhr.responseText;
                alert(xhr.responseText);
        }
        if (xhr.readyState < 4) {
                setTimeout(function() {collectPartial(xhr,lastContent)}, 1000);
        }
}

nph-handleRequest.cgi

#!/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 < 5; $count++) {
        print time();
        print "\n";
        sleep(2);
}

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.

Any suggestions as to what I'm doing wrong would be greatly appreciated.

Edit 1

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.

Edit 2

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.

#!/usr/bin/perl
$|=1;
use CGI::Push qw(:standard);

do_push(-next_page=>\&display_time,-delay=>2);

sub display_time {
        my($q,$counter) = @_;
        return undef if $counter > 5;
        return time()," "x256, "\n";
}