【发布时间】:2013-12-27 15:48:28
【问题描述】:
嗨朋友们,我在使用 .html() 函数时遇到了 dataTables 搜索和排序功能的问题...替换 div 中的内容...替换的内容来自使用此功能的 ajax 请求....
function str(gs)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var strArray = xmlhttp.responseText.split("::");
$("#field1").html(strArray[0]);
$("#fieldb").html(strArray[1]); //this line replaces the content of tbody where datatables search and sort doesn't work
$("#tiger1").html(strArray[2]);
}
}
xmlhttp.open("GET", "data/readv-data.php?scode="+gs, true);
xmlhttp.send();
}
这里是html
<table cellpadding="0" cellspacing="0" border="0" class="display" rel="datatable" id="rep">
<thead>
<tr>
<th>Library</th>
<th>Book</th>
<th>Date</th>
<th>Location</th>
<th>Type</th>
</tr>
</thead>
<tbody id="fieldb">
</tbody>
</table>
【问题讨论】:
-
请提供更多信息。您是说数据根本没有出现,这意味着 .html() 似乎没有工作,或者数据出现但搜索/排序不起作用。如果您看到数据,请在 Chrome 中按 F12,转到控制台选项卡,尝试搜索/排序并告诉我您在控制台中看到的错误。 .html() 和 .text() 似乎对我有用:jsfiddle.net/MmbnK/1 尝试提醒 strArray[1] 以确保您按预期获取数据并且拆分按预期进行。
-
数据即将到来,但可数据排序 n 搜索不起作用....
-
无论如何你是如何使用 jQuery 的,不妨看看 jQuery ajax() 函数。
标签: javascript php jquery ajax jquery-datatables