Hello I have a webpage with an input section that then runs a perl script with the variables from the input section from the page and then returns the results to the same page this is the code for the HTML page
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquer +y.min.js"></script> </head> <body> <div> <input type="text" name="s" placeholder="Search..." id="urlField"> <input type="button" value="Search" id="btnSearch"> </div> <!-- the result of the search will be rendered inside this div --> <div id="result"></div> <p id="content"> Lorem Ipsum </p> <script> $(document).ready(function () { $("#btnSearch").click(function(event) { // Get some values from elements on the page: var term = $("#urlField").val(); perlExecute(term); }); }); function perlExecute(url){ $.ajax({ type: 'POST', url: '/cgi-bin/doma.pl?url='+url, data: { 'url': url }, success: function(res) { alert(res); }, error: function() {alert("did not work");} }); }; </script> </body> </html>
this is the perl script that am calling
#!/usr/bin/perl -w use warnings; use JSON; use CGI; @my_query_string = split(/s=/,$ENV{'QUERY_STRING'}); my $scalar = join( '' , @my_query_string ); my $rec_hash0 = [$scalar]; my $einput = encode_json($rec_hash0); print "Content-type: text/html\n\n"; print "$einput\n";
when i try run the code above I get the alert "did not work" in the apache2 error logs I have the following error
[Tue Mar 01 20:59:32.474858 2016] [cgid:error] [pid 25562] (104)Connec +tion reset by peer: [client 10.2.2.248:53551] AH02550: Failed to flus +h CGI output to client, referer: http://10.2.2.20/1z.html
Am new to Perl can someone help me with getting this to work

In reply to Run a perl script and return results using AJAX without reloading the page by HBMBR

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.