我需要数据表数据处理方面的帮助
我的服务器端处理(数据表)下面的脚本有问题,它不显示来自后端脚本的数据
它只是挂起处理而不显示后端脚本的数据的问题
这是我的后端脚本,它正在工作并返回
{"748847":"Jane Deo"}
#!/usr/bin/perl -wT
use strict;
use warnings;
use DBI;
use JSON;
use CGI qw/:standard/;
my $Cgi = CGI->new();
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];
}
my $json = encode_json(
{ $idnum, $fname}
);
print $Cgi->header( -type => 'application/json' ),$json;
这是我的 html 前端
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/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>
您应该得到答案的一些问题:
file.pl
是否被正确调用? file.pl
是 CGI 程序的正确 URL 吗?您在 Web 服务器访问日志中看到该请求了吗? Web 服务器错误日志中是否有任何内容(尤其是 404 错误)?file.pl
作为 CGI 程序执行? Web 服务器错误日志中是否有任何有用的内容(可能是有关权限错误的内容,也可能是某种 500 错误)?{ "id" : "...", "name" : "..." }
吗?