Solved

please wait message - tell browser to begin opening page so wait message is displayed right away. . .

Posted on 2004-09-09
5
240 Views
Last Modified: 2013-12-25
hello,

 I have cgi which accesses a very large datafile, does some processing and displays the results.  I set up a wait message for this page using the method shown below (see waitpage method).  

The Problem:  the browser does not want to start loading the page (which includes the wait message) until the script is almost finished processing (or perhaps it is waiting for a certain amount of data to be returned before it starts rendering to the next page.)  

I have bypassed this problem by cheating and printing a bunch of spaces before the cgi does the bulk of the processing.  This works, but then of course, it is a waste of time, and it puts a bunch of spaces in the html page source.  

Can someone point out the correct way to do this?

thanks!

waitpage method:
----------------------------------------------------------------------------------------------
#!/usr/bin/perl

wait_header();

#access database
   (some code here);
#process data
   (more code here);
#print results
   (more code here);

wait_footer();


sub wait_header{

print "Content-type:text/html\n\n";
print qq{
<html>
<head>
<title>Please Wait...</title>

<Script>
function showContent() {
  document.getElementById("wait").style.display = "none"
  document.getElementById("content").style.display = "block"
  window.document.title = "Finished";
}
</Script>
</head>
<body onLoad="showContent()">

<div id=wait>
<h3>Accessing Database<h3>
<p>Please wait . . .</p>
<img src="waitbar.gif">
</div>

<div id="content" style="display:none;">
};
}

sub wait_footer{
print qq{
</div>
};
html_footer();
}
0
Comment
Question by:sidikiisajawa
  • 2
  • 2
5 Comments
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 125 total points
ID: 12024769
Try to flush the buffer before you print
print "Content-type:text/html\n\n";
with :

# ------------------------------------------
# Flush buffers and print MIME Content-type
# Header for the output HTML file
# ------------------------------------------

# flush STDOUT buffer
$| = 1;
0
 
LVL 48

Expert Comment

by:hernst42
ID: 12024855
0
 
LVL 3

Accepted Solution

by:
cjmos earned 125 total points
ID: 12026653
Hi,

instead of disabling perl buffering with $| = 1 I'd use the built in IO::Handle module to automatically flush each line of STDOUT.

e.g:

#!/usr/bin/perl
use CGI':standard';
use CGI::Carp "fatalsToBrowser";
use IO::Handle;
STDOUT->autoflush(1);

wait_header();
#access database
   (some code here);
#process data
   (more code here);
#print results
   (more code here);

wait_footer();


etc...

This works in IE, netscape and Mozilla.
0
 

Author Comment

by:sidikiisajawa
ID: 12030179
exactly what i needed, thanks :)
0
 

Author Comment

by:sidikiisajawa
ID: 12031128
both methods work just the same for what I am doing - since I only care about flushing the buffer, and not about print as you go they are doing in http://www.experts-exchange.com/Web/Web_Languages/CGI/Q_21125344.html
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question