This is what i tried, and still not working. it just hangs on Processing...
i first made sure that i get well structured json
#!/usr/bin/perl -wT
use strict;
use warnings;
use DBI;
use JSON;
use CGI qw/:standard/;
use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
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 $Test = $dbh->prepare("SELECT idnum, fname FROM dbuser");
$Test->execute();
my (@data,$idnum,$fname);
foreach (@data = $Test->fetchrow_array()) {
$idnum = $data[0];
$fname = $data[1];
}
print "Content-type: text/html\n\n";
my $json = encode_json(
{ $idnum, $fname}
);
print $json;
OUTPUT IS
{"748847":"Jane Deo"}
And this is my html
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.ne
+t/v/bs-3.3.7/jq-3.3.1/dt-1.10.18/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs/jq
+-3.3.1/dt-1.10.18/datatables.min.js"></script>
<script type="text/javascript" src="https://stackpath.bootstrapcdn.com
+/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<script>
jQuery(function($){
$("#table_id").DataTable({
"processing": true,
"serverSide": true,
"ajax": "file.pl"
});
});
</script>
</head>
<body>
<h1>sample dataTable</h1>
<table id="table_id" class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>NAME</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</body>
</html>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.