Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 956577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:33:35+00:00 2026-05-16T00:33:35+00:00

Is it possible for a perl cgi script to segment its AJAX responses into

  • 0

Is it possible for a perl cgi script to segment its AJAX responses into numerous individual HTTP responses?

Say I have this code:

xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        onDataReceived(xmlhttp.responseText);
    }
    else if(xmlhttp.status!=200 && xmlhttp.status!=0) {    }
}
xmlhttp.open("POST","script.cgi",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(toURLString(options));

as javascript (dont tell me about xml object compatibility issues with ie, I know, and don’t care).

and this:

print "Content-type: text/html\n\n";

my %form = Vars();
if($ENV{REQUEST_METHOD} eq "POST" )
{
    $|=1;
    for(my $i, (1..100000000))
    {
        print "1\n";
    }
}

as perl cgi. Is it possible to print out this result in numerous individual packets of 1s, instead of generating 100000000 1s before finally having an output?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:33:36+00:00Added an answer on May 16, 2026 at 12:33 am

    Please see this SO question for possible approaches, though it’s not Perl specific:

    Dealing with incremental server response in AJAX (in JavaScript)

    From the linked Wiki article, this link seems most relevant: http://en.wikipedia.org/wiki/Comet_%28programming%29#XMLHttpRequest

    However, I would strongly suggest considering a polling approach instead of the “server push” one you are considering:

    The server stores the chunks of data as accessible files (with some ordering meta info)

    print "Location: xxxx"; 
    # Sorry, forgot the exact form of Location HTTP response.
    # Location points to URL mapped to /home/htdocs/webdocs/tmp/chunk_0.html
    my %form = Vars();
    if($ENV{REQUEST_METHOD} eq "POST" )
    {
        $|=1;
        $file_num = 0;
        my $fh;
        for(my $i, (1..100000000))
        {
            if ($i % 1000 == 0) {
                close $fh if $fh;
                open $fh, ">", "/home/htdocs/webdocs/tmp/chunk_${file_num}.html";
                # Add the usual error handling on open/close i'm too lazy to type
                $file_num++;
            }
            print $fh "1\n";
        }
        print $fh "\n##############END_TRANSMISSION__LAST_FILE####################\n";
        # This was a singularly dumb way of marking EOF but you get the drift
        close $fh;
    }
    

    The AJAX poller retrieves them in a loop one by one, processing the response containing the next chunk and looking for meta-info to know what (and if) the next piece to poll for is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to have a Perl script run shell aliases? I am running
I am wondering if it is possible to use a single perl cgi script
I have cgi script pulling search terms from an HTML form through CGI::Ajax .
I have this simple cgi script working just fine but I want to add
Hi guys i have this line of code in a perl script where i
I know this is possible in Perl, but I was wondering if this can
Is it possible to write a script in Perl that opens different URLs and
Something like this: http://perl.plover.com/yak/regex/samples/slide083.html In other words I want to match successfully on {
In Perl it is possible to do something like this (I hope the syntax
Possible Duplicate: How can I make an HTTP GET request from Perl? I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.