How to display a “waiting page” while a CGI is running?

大憨熊 提交于 2019-12-22 08:52:22

问题


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


回答1:


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).




回答2:


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.




回答3:


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>


来源:https://stackoverflow.com/questions/7632717/how-to-display-a-waiting-page-while-a-cgi-is-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!