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 - When it returns the results they are not formatted (with new lines or tabs correctly)
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquer +y.min.js"></script> <script> $(document).ready(function() { $('input').keyup(function() { var empty = false; $('input').each(function() { if ($(this).val().length == 0) { empty = true; } }); if (empty) { $('.actions input').attr('disabled', 'disabled'); } else { $('.actions input').attr('disabled', false); } }); $("#btnSearch").click(function(event) { var term = $("#urlField").val(); perlExecute(term); }); function perlExecute(term){ $.ajax({ type: 'POST', url: '/cgi-bin/domain-.pl', data: { 's': term }, success: function(res) { $("#result").text(res); }, error: function() {$("#result").text("Search Failed\nPossible +reasons:-\nThere illegal characters in your search.)");} }); }; }); </script> </head> <body> <div class='form'> <input type="text" name="s" placeholder="Search..." id="urlField +"> <div class='actions'> <input type="button" value="Search" id="btnSearch" disabled="dis +abled" > </div> </div> <div id="result"></div> <p id="content">Lorem Ipsum</p> </body> </html>
The error code if the script fails to run is return in the webpage like this
Search Failed Possible reasons:- There illegal characters in your sear +ch
With no recognition of the my new-line characters or the other extreme is
["Search Failed\nPossible reasons:-\nThere illegal characters in your +search."]
With my new-line characters printed in the text. - how can I format the error text the way i want it to appear? The other issue is that the command being run is
#!/usr/bin/perl -w use warnings; use JSON; use CGI; my $cgi = CGI->new(); my $string = $cgi->param('s'); $ns_lookup = `dig \@4.2.2.2 +norecurse +nocmd +noquestion +nostats +no +comments +authority +noadditional $domain NS`; chomp($ns_lookup); print "Content-type: text/html\n\n"; print $ns_lookup;
The above code prints out the following
google.co.zw. 59751 IN NS ns3.google.com. google.co.zw. 59751 IN NS ns +4.google.com. google.co.zw. 59751 IN NS ns1.google.com. google.co.zw. + 59751 IN NS ns2.google.com.
Instead of
google.co.zw. 59751 IN NS ns3.google.com. google.co.zw. + 59751 IN NS ns4.google.com. google.co.zw. 59751 IN + NS ns1.google.com. google.co.zw. 59751 IN NS ns2.goog +le.com.
how can i format the text and make it more legible.

In reply to Format script out in JSON for webpage 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.