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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |