Hi

How do I capture the JSON data in a usable manner?

Thanks

Following code executes the CGI script:

<script type="text/javascript"> $(document).ready(function(){ alert("entered function"); $.getJSON("http://www.xxx.org/httpsdocs/cgi-bin/update_tables.cgi?ac +tion=updatetable_167&kind=0&searchterm=19", function(data){ $.each(data, function(key, value){ document.write(key+":"+value+"<br />"); }); }); }); </script

Nothing printed out

Below is log showing that the query was executed and returned the correct values

[Tue Mar 20 19:59:06 2018] update_tables.cgi: searchterm = '19' at upd +ate_tables.cgi line 439. sortindex = '0' at update_tables.cgi line 455. [Tue Mar 20 19:59:06 2018] update_tables.cgi: sortindex = '0' at upda +te_tables.cgi line 455. searchfield = 'user_id' at update_tables.cgi line 457. [Tue Mar 20 19:59:06 2018] update_tables.cgi: searchfield = 'user_id' + at update_tables.cgi line 457. statement = 'SELECT * FROM users WHERE user_id = ? ORDER BY ? ASC' at + update_tables.cgi line 462. count = '1' at update_tables.cgi line 473. [Tue Mar 20 19:59:06 2018] update_tables.cgi: count = '1' at update_ta +bles.cgi line 486. Finished print {"DD":"2019-01-30","DP":"2018-12-31","MD":"120.00","MJ" +:"2018-01-30","address1":"1471 Meeks Rd","address2":null,"business":" +JZ Electroplating","city":"Latham","comments":"This is a test entry", +"email":"jze@yahoo.com","forename":"John","id":57,"lastname":"Zinzer" +,"password":"1234","phone_cell":"517-204-1111","phone_home":"517-233- +4378","pin":"JbwmZ","position":"General Member","state":"NJ","user_id +":19,"username":"lms19","zip":"45789-2334"} at update_tables.cgi line + 492.

JSON print works as I captured output in an IFrame for testing.

my $searchResult = $sth->fetchrow_hashref(); my $count = $sth->rows; warn("count = '$count'"); if ($count == 0) { warn("Failed Search: '$searchfield' equal to '$searchterm' "); my %searchFail = ( SearchError => $kind); my $json = JSON->new; $json->canonical(1); $json = encode_json(\%searchFail); print "Content-Type: application/json\n\n"; print $json; warn("Finished print 0 count $json"); exit(1); } #{"SearchError":0} Good else { warn("count = '$count'"); my $json = JSON->new; $json->canonical(1); $json = encode_json($searchResult); print "Content-Type: application/json\n\n"; print $json; warn("Finished print $json"); exit(0); }

In reply to JSON Return Values by tultalk

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.