Mushal
Mushal

Reputation: 97

How to display a "waiting page" while a CGI is running?

I have a cgi script that takes long time (30 sec) to generate the results before printing out the html. I want to show an intermediary page that says "Loading, please wait..." with an animated GIF before displaying the results. Thanks

Upvotes: 4

Views: 5116

Answers (3)

Mushal
Mushal

Reputation: 97

Thanks guys for the help, this what I did:

<script type="text/javascript">
var ray={
ajax:function(st)
    {
        this.show('load');
    },
show:function(el)
    {
        this.getID(el).style.display='';
    },
getID:function(el)
    {
        return document.getElementById(el);
    }
}
</script>
<style type="text/css">
#load{
position:absolute;
z-index:1;
border:3px double #999;
background:#f7f7f7;
width:300px;
height:300px;
margin-top:-150px;
margin-left:-150px;
top:50%;
left:50%;
text-align:center;
line-height:300px;
font-family:"Trebuchet MS", verdana, arial,tahoma;
font-size:18pt;
}
</style>
<div id="load" style="display:none;">Loading... Please wait<br/><img src="images/loading.gif"></div>
<form action="http://localhost/cgi-bin/test.cgi" method="get" onsubmit="return ray.ajax()">
<input type="text" value="Test" name="q">
<input type="submit" value="Search">
</form>

Upvotes: 3

Adam Jurczyk
Adam Jurczyk

Reputation: 2131

Simple solution: Make static html page, with your loading text and gif, and with an JS script loading your CGI script with XHR. It is very simple with libs like jQuery and its ajax helper functions like load.

Upvotes: 4

Quentin
Quentin

Reputation: 943518

Fork the process and keep a reference to it in a session. Then poll the script periodically for a status update.

There is a more detailed explanation with code examples that was originally published in Linux Magazine. Perl Monks has further discussion.

You could use JavaScript (and XMLHttpRequest) to do your polling instead of reloading the whole page (do remember to build on things that work though).

Upvotes: 4

Related Questions