tags:

views:

306

answers:

1

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,

+2  A: 

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?

RichieHindle
My apache2 DocumentRoot is set to /var/www/ and index.html, example.php jqGrid files are in this directory and they are executed normaly.Whereas perlModule is configured to run from /usr/lib/cgi-bin aliased to cgi-bin.All my perl CGI scripts work fine and are normally handled with apache2.Here is the log error when I access 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) line 69.\n
Yngwie
When I point my browser directly to example.php it shows the XML file but when pointed to the perl's one it shows off an Error. (running ./example.pl gives expected results)Now That I change the line print CGI->header("Content-type: text/xml;charset=utf-8");to print CGI->header;The browser will show this: 111008-01-032412
Yngwie
Ouchhhhh! You Saved me another long day of troubles. You are right it was that about apache error. I thought header() was a static method anyway.. Now everything works just fine Thank you bro you are great.
Yngwie
8-) Happy to help!
RichieHindle