http://www.perlmonks.org?node_id=11157707


in reply to Re^6: Server-side processing?
in thread Server-side processing?

{"748847":"Jane Deo"}

Did you look at any of the DataTables examples? Consider the following:

use DBI; use JSON::XS; my $host = "host"; my $usr = "user"; my $pwd = "pwd"; my $dbname = "datname"; my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, { RaiseError => 1, }) or die $DBI::errstr; my $json; $json->{data} = $dbh->selectall_arrayref('SELECT idnum, fname FROM dbu +ser', {Slice => {}} ); warn encode_json( $json );
print "Content-type: text/html\n\n";

JSON isn't html: application/json, and why are you manually printing headers when you're using CGI which has a method for that?

Replies are listed 'Best First'.
Re^8: Server-side processing?
by hippo (Bishop) on Feb 15, 2024 at 11:59 UTC
    why are you manually printing headers when you're using CGI which has a method for that?

    Good question. ISTM that the code provided by frank1 isn't actually using CGI.pm at all for anything. So I would suggest just keeping the explicitly printed header and ditch the loading of CGI.pm instead. A single header is as easy to print by hand as it is using the CGI header method.


    🦛

      Based on how the previous threads have gone, I suspect what's being posted isn't necessarily representative of what's going on, in so far as the first post mentions 300K records I'd suspected that there could be the intention of some search criteria, so people could filter and/or DataTables paging would be intended for use since rendering that amount of data in one wouldn't be a great end user experience.

Re^8: Server-side processing?
by frank1 (Scribe) on Feb 15, 2024 at 12:32 UTC
    HASH(0x55cf3f782d88)

    thats what i get

      Then you didn't run what I wrote, I suspect you've decided to do something like this?

      $json->{data} = $dbh->selectall_arrayref('SELECT idnum, fname FROM dbu +ser', {Slice => {}} ); print $json ;

      outputting:

      HASH(0x55e405886718)