Solved

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

Posted on 2004-09-09
5
236 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

813 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

17 Experts available now in Live!

Get 1:1 Help Now