如何在包含的 PHP 页面处理/加载时显示 Prelaoder/加载动画/gif/百分比?

发布于 2024-11-26 01:06:25 字数 1035 浏览 1 评论 0原文

我在 PHP 主页面中包含了一个 PHP 脚本。

帮助我“如何在包含的 PHP 脚本处理和加载时显示预加载/加载动画或 gif 或 swf 或简单的加载百分比?” 这是我想要显示相同内容的代码片段(请参阅最后一行代码):

<body onLoad="document.forms.form1.from.focus()">
<font face="Calibri">
<table cellpadding="10">
   <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="form1">
<tr>
<td width='25%'>
    <fieldset>
        <legend>Enter From & To Date</legend>
        <table border='0'>
        <tr>
            <td>From </td>
            <td><input type="text" name="from" /></td>
        </tr>
    </fieldset>
            <input type="submit" name="submit" value="Submit" />
</td>
</tr>
</form>
</table>
<?  
//Form submitted
if(isset($_POST['submit'])) 
{
    //No errors, process
    if(!@is_array($error)) 
    {  
 HERE IS WHERE I WANT THE LOADING TO TAKE PLACE
//HERE I INCLUDE THE SCRIPT

另外,如果我可以延迟 PHP 脚本的显示,直到它完成处理。

I'm including a PHP script with in a main PHP page.

Help me "how to show a Preloader/loading animation or gif or swf or simply percentage of loading while the included PHP script processes & loads?"
Here is the code snippet where I want to show the same (See the last line of code):

<body onLoad="document.forms.form1.from.focus()">
<font face="Calibri">
<table cellpadding="10">
   <form action="<?=$_SERVER['PHP_SELF']?>" method="post" name="form1">
<tr>
<td width='25%'>
    <fieldset>
        <legend>Enter From & To Date</legend>
        <table border='0'>
        <tr>
            <td>From </td>
            <td><input type="text" name="from" /></td>
        </tr>
    </fieldset>
            <input type="submit" name="submit" value="Submit" />
</td>
</tr>
</form>
</table>
<?  
//Form submitted
if(isset($_POST['submit'])) 
{
    //No errors, process
    if(!@is_array($error)) 
    {  
 HERE IS WHERE I WANT THE LOADING TO TAKE PLACE
//HERE I INCLUDE THE SCRIPT

Also, if i can delay the display of the PHP script until it completes processing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无语# 2024-12-03 01:06:25

将包含加载屏幕的

放在 之后(或者至少在耗时的加载发生之前)。在最后(或者在应该被加载屏幕覆盖的长部分之后)添加一些 JavaScript 来隐藏/删除包含加载屏幕的 div。

Put a <div> containing your loading screen right after the <body> (or at least before the time-consuming loading happens). At the very end (or after the long part which should be covered by the loading screen) add some JavaScript to hide/remove the div containing the loading screen.

纵情客 2024-12-03 01:06:25

这是我从互联网上下载的脚本的修改版本。不记得我从哪里得到它抱歉。

<html>
<head>
<script type="text/javascript">
function swapdiv() { 
    //Hide the loading div
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('loadingdiv').style.display = 'none'; 
    } else { 
        if (document.layers) { // Netscape 4 
            document.loadingdiv.display = 'none'; 
        } else { // IE 4 
            document.all.loadingdiv.style.display = 'none'; 
        } 
    } 

    //Show the results div
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('resultdiv').style.display = 'block'; 
    } else { 
        if (document.layers) { // Netscape 4 
            document.resultdiv.display = 'block'; 
        } else { // IE 4 
            document.all.resultdiv.style.display = 'block'; 
        } 
    } 

    window.onunload = null;
    return;
} 
</script>
</head>
<body>
<form name="form1">
</form>
<div id='loadingdiv' align='center'><img src='../images/loading.gif' alt='Loading...' title='Loading...' /></div>
<div id='resultdiv' style='display:none;'>
<!-- Do some html stuff here. This div block is hidden until the end of page load -->
<?php
    //Query database
    //Show results
?>
</div>
<script type='text/javascript'>
    //this is called after page loaded
    window.onload=swapdiv;
</script>
</body>
</html>

This is my modified version of a script I got off the internet. Cant remember where I got it from sorry.

<html>
<head>
<script type="text/javascript">
function swapdiv() { 
    //Hide the loading div
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('loadingdiv').style.display = 'none'; 
    } else { 
        if (document.layers) { // Netscape 4 
            document.loadingdiv.display = 'none'; 
        } else { // IE 4 
            document.all.loadingdiv.style.display = 'none'; 
        } 
    } 

    //Show the results div
    if (document.getElementById) { // DOM3 = IE5, NS6 
        document.getElementById('resultdiv').style.display = 'block'; 
    } else { 
        if (document.layers) { // Netscape 4 
            document.resultdiv.display = 'block'; 
        } else { // IE 4 
            document.all.resultdiv.style.display = 'block'; 
        } 
    } 

    window.onunload = null;
    return;
} 
</script>
</head>
<body>
<form name="form1">
</form>
<div id='loadingdiv' align='center'><img src='../images/loading.gif' alt='Loading...' title='Loading...' /></div>
<div id='resultdiv' style='display:none;'>
<!-- Do some html stuff here. This div block is hidden until the end of page load -->
<?php
    //Query database
    //Show results
?>
</div>
<script type='text/javascript'>
    //this is called after page loaded
    window.onload=swapdiv;
</script>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文