PHP进度条

发布于 2024-09-07 08:26:29 字数 1007 浏览 2 评论 0原文

我有一个表单,如下所示:

Page 1:

<form name = "form1" method="post" action = "page2.php">
........
</form>

Page2.php:

<?php

For loop ...
.....
end

?>

现在我想在第 1 页上有进度条,以便它可以显示 page2.php 中 for 循环的完成进度。

告诉我我该怎么做?请不要将我定向到任何进度栏,我已经在使用进度,但我不知道如何在其中实现代码,

以下是我当前正在使用的代码,

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.progressbar.min.js"></script> 

$(document).ready(function() { 
$("#spaceused1").progressBar(); 
}); 
HTML:

<span class="progressBar" id="spaceused1">25%</span> 

<a href="#" onclick="$('#spaceused1').progressBar(20);">20</a> 
<a href="#" onclick="$('#spaceused1').progressBar(40);">40</a> 
<a href="#" onclick="$('#spaceused1').progressBar(80);">80</a> 

当我单击上面时,它工作正常链接。但是我如何在 page1 上显示它以显示 page2.php 上 for 循环的进度?

请帮帮我。

I have one form as shown below:

Page 1:

<form name = "form1" method="post" action = "page2.php">
........
</form>

Page2.php:

<?php

For loop ...
.....
end

?>

Now i want to have progress bar on page 1 so that it can show the completion progress of for loop in page2.php.

Tell me how can i do that? Please don't direct me to any progress bar i'm already using the progress but i don't know how to implement the code into it,

The following is the code i'm currently using

<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript" src="jquery.progressbar.min.js"></script> 

$(document).ready(function() { 
$("#spaceused1").progressBar(); 
}); 
HTML:

<span class="progressBar" id="spaceused1">25%</span> 

<a href="#" onclick="$('#spaceused1').progressBar(20);">20</a> 
<a href="#" onclick="$('#spaceused1').progressBar(40);">40</a> 
<a href="#" onclick="$('#spaceused1').progressBar(80);">80</a> 

It works fine when i click on the above links. But how can i show it on page1 to show the progress of for loop on page2.php?

Please help me out.

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

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

发布评论

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

评论(3

你的笑 2024-09-14 08:26:29

Page2.php:

<?php

for(;;) {
    //In each loop iteration, update your progress and store it in the session
    $_SESSION['myFormProgress'] = myProgressCalculation();
}

?>

然后使用 AJAX 轮询服务器,接收 $_SESSION['myFormProgress'] 的当前值,并相应地更新进度条。

正如 Jonah Bron 指出的那样,您还需要使用 AJAX 将表单提交到 Page2.php。否则,您将无法继续在页面上运行 JavaScript(以更新进度条)。当 for 循环完成(并且进度条已满)时,我怀疑您会希望将用户重定向到可以看到结果的新页面。

Page2.php:

<?php

for(;;) {
    //In each loop iteration, update your progress and store it in the session
    $_SESSION['myFormProgress'] = myProgressCalculation();
}

?>

And then use AJAX to poll the server, receive the current value of $_SESSION['myFormProgress'], and update your progress bar accordingly.

As Jonah Bron points out, you'll also need to submit your form to Page2.php using AJAX. Otherwise, you won't be able to continue running JavaScript on the page (to update the progress bar). When the for loop is finished (and the progress bar is full), I suspect you will want to redirect the user to a new page where the results can be seen.

一袭白衣梦中忆 2024-09-14 08:26:29

如果我正确理解您的问题,您将需要使用 Ajax 来提交表单。我不使用 jQuery,所以我不知道如何使用 XMLHttpRequest 实现进度条。

If I understand your question correctly, you'll need to use Ajax to submit the form. I don't use jQuery, so I don't know how to implement the progressbar with an XMLHttpRequest.

随波逐流 2024-09-14 08:26:29

通过常规 Ajax 很难做到这一点,您必须稍微修改服务器,因为 PHP 不支持它。

您可能会对一个允许 php 执行此操作的扩展感兴趣。

模块页面: http://pecl.php.net/package/uploadprogress/1.0.1

示例: http://svn.php.net/viewvc /pecl/uploadprogress/trunk/examples/

this is pretty dificult to do via regular Ajax, You have to mod the server slightly as PHP Does not support it.

Theres is an extention you may be interested in that allows php to do this.

Module Page: http://pecl.php.net/package/uploadprogress/1.0.1

Examples: http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文