Solved

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

Posted on 2004-09-09
5
226 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
Comment Utility
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
Comment Utility
0
 
LVL 3

Accepted Solution

by:
cjmos earned 125 total points
Comment Utility
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
Comment Utility
exactly what i needed, thanks :)
0
 

Author Comment

by:sidikiisajawa
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now