使用 jQuery 和 Perl 的数据表问题

问题描述 投票:0回答:1

我需要数据表数据处理方面的帮助

我的服务器端处理(数据表)下面的脚本有问题,它不显示来自后端脚本的数据

它只是挂起处理而不显示后端脚本的数据的问题

这是我的后端脚本,它正在工作并返回

{"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>
javascript jquery ajax perl
1个回答
0
投票

您应该得到答案的一些问题:

  1. Ajax 调用 -
    file.pl
    是否被正确调用?
    file.pl
    是 CGI 程序的正确 URL 吗?您在 Web 服务器访问日志中看到该请求了吗? Web 服务器错误日志中是否有任何内容(尤其是 404 错误)?
  2. CGI 程序调用 - Web 服务器是否正确配置为将
    file.pl
    作为 CGI 程序执行? Web 服务器错误日志中是否有任何有用的内容(可能是有关权限错误的内容,也可能是某种 500 错误)?
  3. 返回的数据 - 您是否在浏览器的开发人员工具的网络选项卡中看到返回的预期数据?这是您配置数据表的正确数据格式吗?您确定不想要
    { "id" : "...", "name" : "..." }
    吗?
© www.soinside.com 2019 - 2024. All rights reserved.