Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:47:01+00:00 2026-06-15T10:47:01+00:00

#!/usr/bin/perl # perl cgi script products2.cgi use DBI; print <<END_HTML; Content-type: text/html END_HTML my

  • 0
  #!/usr/bin/perl 
  # perl cgi script products2.cgi 


use DBI;
print <<END_HTML;
Content-type: text/html
END_HTML
my $host = "xxx.xxx.xxx";
my $port = "xxxx";
my $database = "proj4";
my $username = "xxxxxx";
my $password = "xxxxx";
my $database_source = "dbi:mysql:$database:$host:$port";


my $dbh = DBI->connect($database_source, $username, $password) 
or die 'Cannot connect to db';

my $sth = $dbh->prepare("SELECT distinct category FROM products");
$sth->execute();

#getting the categories and displaying them
while(my @row=$sth->fetchrow_array()) {
my $data =$row[0];
 my @values = split(' ',$data);
my $pic = "/~xxxx/proj4/images/".$values[0].".jpg";
print <<END_HTML;
<div class="view view-first">
END_HTML

print"<img src=\"$pic\" alt=\"$row[0]\"/>"; 
print "<h2 class=\"choc\"><span>$row[0]</span></h2>";
print "<div class=\"mask\">"; 
print "<h2 class=\"eff\">\"$row[0]\"</h2>";
print <<END_HTML; 
 <p>One of Our best sellers</p>  
     <a href="#" class="info $values[0]">Discover</a>  
 </div>   
 </div>  
END_HTML
 }


 $sth->finish();
 $dbh->disconnect();

I am trying to replace the contents of

  <div id="content"></div> 

in my proj.html to the output of the above perl script when clicked on “products” link in the navigation bar.

//navigation bar for product

 <li>
<a href="/perl/xxxxx/products2.cgi" id="productit">
Products
</a>
 </li>

I know I have to use javascript and ajax, but not sure how to do it.

 $('#productit').bind('click', function() {

 var handle = document.getElementById('content');

  var req = new HttpRequest('/perl/xxxxx/products2.cgi', callback); 
  //i know this ajax call only expects string to be returned from server
 req.send();  

 handle.innerHTML= //not sure how to populate this                  
 });

Could someone please guide me as to how to send html ready to display from the perl script

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:47:03+00:00Added an answer on June 15, 2026 at 10:47 am

    All you have to do is print the HTML and it gets sent to the client/browser.

    However…

    I notice one minor detail in your Perl code which would cause the web server to throw a 500 Internal Server Error: You forgot to print a blank line after your HTTP headers. The code posted would send the output

    Content-type: text/html
    <div class="view view-first">
    ...
    

    which is not a valid HTTP response because <div is not a recognized HTTP header. It needs to send

    Content-type: text/html
    
    <div class="view view-first">
    ...
    

    instead, with a blank line to indicate the end of headers before the content starts.

    This is one of the reasons why it’s generally a good idea to use a web framework (such as Dancer, Mojolicious, or Catalyst) or even the arcane CGI.pm instead of handling these things manually: there are so many minor details and strange edge cases that you need to get just right or else it will fail to work for no apparent reason. If this is a learning exercise, rolling your own is fine and it’s good to learn where all those pitfalls are, but you’re better off using a widely-used and well-tested module to deal with them in code whose purpose is to do something useful or important.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in the html file: <!--#exec cgi=/cgi-bin/test.pl--> the perl script: #!/usr/bin/perl print Content-Type: text/html\n\n; print
#!/usr/bin/perl print Content-type: text/html \n\n; print qq(<html> <head> <script type=text/javascript src=/jquery.js></script> <script> jQuery(document).ready(function(){ jQuery(#form_lang).submit(function(e){
I am trying to run this script mail.pl #!/usr/bin/perl print Content-type: text/html \n\n; #HTTP
I have a perl.cgi file which has the content: #!/usr/bin/perl print Content-type: text/html\n\n; print
I have run this Perl code: #!/usr/bin/perl print content-type: text/html \n\n; print Hello World.\n;
I am using the following script: #!/usr/local/bin/perl -wT use strict; use warnings; print Content-type:
So I have a cgi script, #!/usr/bin/perl -T use strict; use warnings; use DBI;
i have something like: #!/usr/bin/perl use strict; use warnings; use CGI::Simple; use DBI; my
I have a Perl script called replaceUp: #!/usr/bin/perl search=$1 replace=$2 find . -type f
I've got this simple Perl script: #! /usr/bin/perl -w use strict; use Data::Dumper; my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.