【发布时间】:2021-08-28 23:15:01
【问题描述】:
我想使用 datatables.net 阅读这个 txt 文件 https://www.rapidtech1898.com/aaadownload/arrays.txt
但是当我想将文件与以下文件一起使用时,输出不起作用我在 chrome 检查器中出现此错误: (数据表没有按预期读取,检查员向我展示了这一点)
(起初我在本地有 txt 文件,并读到使用带有本地文件的 chrome 存在一些问题 - 但这是一个“正常”的 http 链接,不是吗? - 为什么这仍然不起作用符合预期?
我有一个 index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css">
</head>
<body>
<div class="container py-5">
<header class="text-center text-white">
<h1 class="display-4">Levermann Scores</h1>
</header>
<div class="row py-5">
<div class="col-lg-10 mx-auto">
<div class="card rounded shadow border-0">
<div class="card-body p-5 bg-white rounded">
<div class="table-responsive">
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Extn.</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="mainAJAX.js"></script>
</body>
</html>
这是 mainAJAX.js 文件:
$(document).ready(function() {
$('#example').DataTable( {
// "ajax": "http://localhost:2121/arrays.txt"
"ajax": "https://www.rapidtech1898.com/aaadownload/arrays.txt"
} );
} );
有人告诉我 - 如果服务器也托管在同一个域(如 rapidtech1898.com)上,它可能会工作。但是,在将其部署到其他地方之前,有没有办法在本地测试这种想法?
【问题讨论】: