Solved

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

Posted on 2004-09-09
5
246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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