简体   繁体   中英

Why does my jqGrid script work fine with PHP but fail with Perl?

Here is client Side code:

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} ],
  });
});

Here is example.php code:

<?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>"; 
?>

Till now everything is just fine, but if now I try to get xml data from my perl cgi script it won't work, and data is not displayed.

Here is the perl code:

#!/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>"; 

and in the jqGrid code I put on url = 'cgi-bin/example.pl',

As you can notice the perl and php codes are similar but don't do the same thing why ?

If you got any hints on how to debug this, please forward. Thanks,

A couple of suggestions:

#1: In your jQuery code you have this:

url:'example.php'

but then you say that for your Perl code you change it to this:

url = 'cgi-bin/example.pl'

Is that right, that one has a cgi-bin/ prefix and the other doesn't?

#2 : What happens if you simply point your browser at the URL of your Perl script? Does it show the XML? What I'm wondering is whether your web server is correctly configured to run PHP, but not correctly configured to run Perl.

Edit - #3: The way you're using Perl's CGI module looks odd to me (though I'm not a Perl guy). I think this is the more idiomatic use:

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

Does that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM