Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何显示进度条直到我的页面加载?_Php_Jquery_Html - Fatal编程技术网

Php 如何显示进度条直到我的页面加载?

Php 如何显示进度条直到我的页面加载?,php,jquery,html,Php,Jquery,Html,我使用php从数据库中获取一些信息,我想显示一个进度条,直到我的php执行为止,我需要在php执行之后显示我的页面。我怎样才能做到这一点 非常喜欢gmail加载收件箱的方式 而且 这相当简单。根据描述,我不知道这个进度条需要有多深。这是应该让您开始的伪代码。它不会按原样运行。。。您需要让这些函数做一些事情 示例1:100%客户端检查器 <script type="text/javascript"> /* in document head */ var section1 = 0; va

我使用php从数据库中获取一些信息,我想显示一个进度条,直到我的php执行为止,我需要在php执行之后显示我的页面。我怎样才能做到这一点

非常喜欢gmail加载收件箱的方式 而且


这相当简单。

根据描述,我不知道这个进度条需要有多深。这是应该让您开始的伪代码。它不会按原样运行。。。您需要让这些函数做一些事情

示例1:100%客户端检查器

<script type="text/javascript">
/* in document head */
var section1 = 0;
var section2 = 0;
var section3 = 0;
var section4 = 0;

//lightbox w/ progress meter
showProgressLightBox();

//async ajax calls here to load the various sectoins
loadPage(); // not a real function



function displayProgressMeter()
{
   var count = 0;
   if (section1) count++;
   if (section2) count++;
   if (section3) count++;
   if (section4) count++;

   if (count != 4) {
     displayProgress(count); //will repaint lightbox progress meter
       //based on X of Y sections loaded
       setTimeout('displayProgressMeter()',500);
   }
   else
   {
        closeLightBox(); //page is loaded
   }

}

displayProgressMeter(); //start the event

//note my ajax calls will flip the values of the various variables we are checking


</script>

/*在文件头中*/
var截面1=0;
var段2=0;
var段3=0;
var段4=0;
//带进度计的灯箱
showProgressLightBox();
//异步ajax在这里调用以加载各个扇区
loadPage();//不是真正的函数
函数displayProgressMeter()
{
var计数=0;
如果(第1节)计数++;
如果(第2节)计数++;
如果(第3节)计数++;
如果(第4节)计数++;
如果(计数!=4){
显示进度(计数);//将重新绘制灯箱进度表
//基于加载的X/Y截面
setTimeout('displayProgressMeter()',500);
}
其他的
{
closeLightBox();//页面已加载
}
}
显示进度表()//启动活动
//注意,我的ajax调用将翻转我们正在检查的各种变量的值
示例2服务器检查器。我为一个项目运行了类似这样的程序,运行某个活动大约需要30分钟。通过从cron调度任务更新mysql来更新进度本身

首先,我有一个名为“batchStatusChecker”的PHP文件,它看起来像这样:

<?php
define('AREA',"COLREPORT");
include(__DIR__."/../phoenix/includes/config.php");
session_start();


$batch=(int)@$_REQUEST["batch"];
include (__DIR__."/affiliateUploadClass.php");

$rs=Query("select commitMessage from phx_AffiliateUsersFiles where ID=$batch;");

echo json_encode(array("info" => $rs->Get("commitMessage")));



?>

然后我有一些javascript,用当前状态更新div或显示完成消息。如果这样的技术更适合您的用例,您可以根据您的需要调整它

    function checkStatusOfReport()
    {

        $.post("/affiliateUpload/batchStatusChecker.php", { "batch": <? echo $batch; ?> },
        function(data)
        {
            if (data.error)
            {
                $("#ErrorInformation").html(data.error);
                $("#UploadInformation").remove();
            }
            else
            {
                var msg="<h3>" + data.info + "</h3>";

                $("#UploadInformation").html(msg);

                if (data.info == 'COMPLETE')
                    $("#UploadInformation").html('<h3>The import of this batch is completed.</h3>');
                else
                    setTimeout("checkStatusOfReport()",4000);


            }
        }, "json");

    }

    checkStatusOfReport();
函数checkStatusOfReport()
{
$.post(“/affiliateUpload/batchStatusChecker.php”,{“batch”:},
功能(数据)
{
if(data.error)
{
$(“#ErrorInformation”).html(data.error);
$(“#上载信息”).remove();
}
其他的
{
var msg=“”+data.info+”;
$(“#上传信息”).html(msg);
如果(data.info==“完成”)
$(“#UploadInformation”).html('此批的导入已完成');
其他的
setTimeout(“checkStatusOfReport()”,4000);
}
}“json”);
}
checkStatusOfReport();

进度条

进度条假定页面以多个步骤加载。使用Javascript(或使用Google可以找到的许多现成方法中的任何一种)在页面中绘制进度条,并为每个步骤推进进度条。你的问题太模糊了。你尝试了什么?为了补充@RobertHarvey所说的。您所寻找的内容实际上只能在初始页面加载之后使用AJAX来加载页面组件。所以基本的工作流程是浏览器发出请求。服务器/PHP应用程序用显示进度条的初始HTML进行回复。然后使用AJAX异步加载页面组件,同时更新进度条。检查页面中加载的组件。。。在填写每个进度表时推进进度表。一旦所有组件都存在,则隐藏overlay@ladieu如何检查加载的组件?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
    <title>Progress Bar</title>
</head>
<body>
<!-- Progress bar holder -->
<div id="progress" style="width:500px;border:1px solid #ccc;"></div>
<!-- Progress information -->
<div id="information" style="width"></div>
<?php
// Total processes
$total = 2;

// Loop through process
for($i=1; $i<=$total; $i++){
    // Calculate the percentation
    $percent = intval($i/$total * 100)."%";

    // Javascript for updating the progress bar and information
    echo '<script language="javascript">
    document.getElementById("progress").innerHTML="<div style=\"width:'.$percent.';background-color:#ddd;\">&nbsp;</div>";
    document.getElementById("information").innerHTML="'.$i.' row(s) processed.";
    </script>';


// This is for the buffer achieve the minimum size in order to flush data
    echo str_repeat(' ',1024*64);


// Send output to browser immediately
    flush();


// Sleep one second so we can see the delay
    sleep(1);
}

// Tell user that the process is completed
echo '<script language="javascript">document.getElementById("information").innerHTML="Process completed"</script>';
?>
</body>
</html>