数据表未加载其功能
function loadmaincattable(){
var xmlhttp;
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)
{
document.getElementById("loadmaincat").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","category-mang/ajax/category-table.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(null);
}
以下是我的category-table.php
文件
<div class="panel-body">
<div class="table-responsive">
<table id="datatable1" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered">
<thead>
<tr>
<th>#</th>
<th>Category Name</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php include("../../All-In-One/select/selectclass.php");
@session_start();
ob_start();
?>
<?php
error_reporting(E_ALL);
$i = 0;$id=1;
$main_array = array();
$select = new SelectQuery();
// simple select query start
$table = "mojo_cart_category"; // table name
$columns = "*"; // table columns name
$where = ""; // where condition
$orderby = "mcat_id"; // orderby column name
$orderbyorder = "DESC"; // orderby order: ASC/DESC
$limit = ""; // set limit
//Don't Change below code, Change at Your Own Risk.
$cnt = $select -> selectCountData($table,$columns,$where);
if($cnt > 0)
{
$sql = $select -> selectData($table,$columns,$where,$orderby,$orderbyorder,$limit);
foreach ($sql as $row_sql)
{
?>
<tr>
<td><?php echo $id; ?></td>
<td><?php echo $row_sql['mcat_name']; ?></td>
<td><?php echo "<a href='category-mang/update-category.php?mid=".$row_sql['mcat_id']."' target='_blank'>Update</a>"; ?></td>
<td><a href='javascript:deleteMainCat(<?php echo $row_sql['mcat_id']; ?>)'>Delete</a></td>
</tr>
<?php
$id++;
}
}
?>
</tbody>
</table>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#datatable1').dataTable({
"sPaginationType" : "bs_four_button"
});
$('#datatable1').each(function() {
var datatable = $(this);
// SEARCH - Add the placeholder for Search and Turn this into in-line form control
var search_input = datatable.closest('.dataTables_wrapper').find('div[id$=_filter] input');
search_input.attr('placeholder', 'Search');
search_input.addClass('form-control input-sm');
// LENGTH - Inline-Form control
var length_sel = datatable.closest('.dataTables_wrapper').find('div[id$=_length] select');
length_sel.addClass('form-control input-sm');
});
});
</script>
我使用javascript-ajax来获取主文件中的数据表
我从表和数据表中得到了所有记录
但是没有获得数据表的功能。
任何人都可以帮助我
答案 0 :(得分:0)
从$(document).ready(function() {
中的<script>
部分删除category-table.php
:
<script type="text/javascript">
$('#datatable1').dataTable({
"sPaginationType" : "bs_four_button"
});
...
</script>
原因:在AJAX请求完成时已经加载了DOM,因此ready()
部分永远不会触发<script>
== dataTables永远不会被初始化。除此之外,ready()
是不可靠的 - 您的AJAX请求中包含的脚本将自动执行。