【发布时间】:2021-03-16 06:32:44
【问题描述】:
我正在尝试将文本文件加载到 JQuery 数据表中。这是我为按下按钮设置的 HTML
<div style="text-align:center;padding:20px 0px 0px 0px;">
<span class="badge badge-info" style="font-size: 1.5rem; font-weight: 700;padding-bottom: 10px;margin-bottom: 20px;" id="txtFile">Get Registered Names</span>
</div>
这是我为实际的 JQuery 数据表设置的 html
<div>
<table id="tblData" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
</table>
</div>
这是我想用来从文本文件中加载表格的 JQuery
$(function (){
$('#txtFile').click(function() {
$('#tblNames').dataTable({
"ajax": 'registeredusers.txt',
"columnDefs":
[{
"data": "Name"
}]
});
});
});
此文件位于/var/www/html/,我想在按钮按下事件时将其显示给用户。我该怎么做?
【问题讨论】:
-
此链接对您有帮助吗?并尝试通过浏览器访问的文本文件stackoverflow.com/questions/29307354/…。
-
@vimuth - 我可以将此
"ajax": "data/object.txt",设置为我的本地路径'"ajax": "/var/www/html/names.txt" -
不应该只是'names.txt'。如果它不起作用,也试试 '/names.txt'。它应该可以从这样的浏览器中看到。datatables.net/examples/ajax/data/arrays.txt。例如:-
"ajax": "names.txt" -
@vimuth - 我收到此错误
DataTables warning: table id=tblDomains - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1 -
你能分享.txt文件的链接,以便我检查json格式是否正确吗?
标签: javascript jquery datatables