【问题标题】:How to create a countdown cgi script in perl?如何在 perl 中创建倒计时 cgi 脚本?
【发布时间】:2012-07-18 09:14:35
【问题描述】:

我正在尝试创建一个从 10 倒数到 0 的简单 cgi perl 脚本;但是我似乎无法让它工作。它一直告诉我malformed header from script. Bad header=HTTP/1.1 200 OK。我是 Perl 和 CGI​​ 脚本的新手,所以我确信这非常简单。

#!/usr/bin/perl
use warnings;
use strict;

use CGI::Push qw(:standard);

my $startingCountDown = 10;

do_push(-next_page => \&refresh, -last_page=> \&lastPage, -delay => 1 );

sub refresh
{
        my ($cgi, $count) = @_;

        return undef if ($startingCountDown - $count < 0);

        my $num = $startingCountDown - $count;
        my $page = $cgi->start_html();
        $page .= $cgi->p("The count is $num").end_html();
        return $page;
}

sub lastPage
{
     my ($cgi, $count) = @_;
    return start_html()."Blast Off".end_html();
}

如果我从终端(在我的 Macbook 上)运行它,我会收到以下错误:WARNING: YOUR BROWSER DOESN'T SUPPORT THIS SERVER-PUSH TECHNOLOGY.。我试过在 Safari 和 Chrome 中运行这个脚本,但似乎都不起作用。在那种情况下,我将如何编写一个从 10 倒数到 1、每秒更改数字的功能脚本?谢谢。

【问题讨论】:

    标签: perl cgi


    【解决方案1】:

    CGI::Push 使用的“服务器推送”机制(特别是multipart/x-mixed-replace)并未得到广泛支持。您将需要选择一种不同的方式来实现这一点;可能最好的方法是让倒计时发生在 Javascript 中,而不是在服务器端。

    【讨论】:

      猜你喜欢
      • 2010-11-29
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 2015-05-05
      • 2012-01-19
      相关资源
      最近更新 更多