【问题标题】:Why does my jqGrid script work fine with PHP but fail with Perl?为什么我的 jqGrid 脚本在 PHP 上运行良好,但在 Perl 上却失败了?
【发布时间】:2010-11-21 18:04:21
【问题描述】:

这是客户端代码:

jQuery(document).ready(function(){
  jQuery("#list").jqGrid({
    url:'example.php',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
    colModel :[ 
      {name:'invid', index:'invid', width:55}, 
      {name:'invdate', index:'invdate', width:90}, 
      {name:'amount', index:'amount', width:80, align:'right'}, 
      {name:'tax', index:'tax', width:80, align:'right'}, 
      {name:'total', index:'total', width:80, align:'right'}, 
      {name:'note', index:'note', width:150, sortable:false} ],
  });
});

这里是example.php代码:

<?php 

header("Content-type: text/xml;charset=utf-8");
print "<?xml version='1.0' encoding='utf-8'?>";
print "<rows>";
print "<page>1</page>";
print "<total>1</total>";
print "<records>1</records>";

print "<row>";
print "<cell>0</cell>";
print "<cell>08-01-03</cell>";
print "<cell>2</cell>";
print "<cell>4</cell>";
print "<cell>12</cell>";
print "<cell><![CDATA[Aiutooooooooo]]></cell>";
print "</row>";
print "</rows>"; 
?>

到目前为止一切都很好,但是如果现在我尝试从我的 perl cgi 脚本中获取 xml 数据 它不起作用,并且数据不显示。

这里是perl代码:

#!/usr/bin/perl

use CGI;

print CGI->header("Content-type: text/xml;charset=utf-8");
print "<?xml version='1.0' encoding='utf-8'?>";
print "<rows>";
print "<page>1</page>";
print "<total>1</total>";
print "<records>1</records>";

print "<row>";
print "<cell>0</cell>";
print "<cell>08-01-03</cell>";
print "<cell>2</cell>";
print "<cell>4</cell>";
print "<cell>12</cell>";
print "<cell><![CDATA[Aiutooooooooo]]></cell>";
print "</row>";
print "</rows>"; 

在 jqGrid 代码中我把 url = 'cgi-bin/example.pl',

你可以注意到 perl 和 php 代码是相似的,但是为什么不做同样的事情呢?

如果您对如何调试有任何提示,请转发。 谢谢,

【问题讨论】:

    标签: php jquery perl


    【解决方案1】:

    几个建议:

    #1: 在你的 jQuery 代码中你有这个:

    url:'example.php'
    

    但是你说你的 Perl 代码你把它改成这样:

    url = 'cgi-bin/example.pl'
    

    对吗,一个有cgi-bin/前缀而另一个没有?

    #2:如果您只是将浏览器指向 Perl 脚本的 URL,会发生什么?它是否显示 XML?我想知道的是您的 Web 服务器是否正确配置为运行 PHP,但 not 正确配置为运行 Perl。

    编辑 - #3: 你使用 Perl 的 CGI 模块的方式对我来说看起来很奇怪(尽管我不是 Perl 人)。我认为这是更惯用的用法:

    use CGI;
    my $cgi = new CGI;
    print $cgi->header("Content-type: text/xml;charset=utf-8");
    

    这有帮助吗?

    【讨论】:

    • 我的 apache2 DocumentRoot 设置为 /var/www/ 和 index.html,example.php jqGrid 文件都在这个目录中,它们可以正常执行。而 perlModule 配置为从别名为 cgi-bin 的 /usr/lib/cgi-bin 运行。我所有的 perl CGI 脚本都可以正常工作,通常由 apache2 处理。这是我访问 url='cgi-bin/example.pl' [Fri Aug 21 20:16:01 2009] [error] Can't call method "send_cgi_header" on an undefined value at (eval 7)第 69 行。\n
    • 当我将浏览器直接指向 example.php 时,它会显示 XML 文件,但是当指向 perl 的文件时,它会显示错误。 (运行 ./example.pl 会给出预期的结果)现在我更改了行 print CGI->header("Content-type: text/xml;charset=utf-8");打印 CGI-> 标题;浏览器会显示:111008-01-032412
    • 哎呀!你让我又度过了漫长的一天。你是对的,这是关于 apache 错误的。无论如何,我认为 header() 是一个静态方法。现在一切正常 谢谢兄弟,你很棒。
    猜你喜欢
    • 2021-07-22
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    相关资源
    最近更新 更多