将 datatables.js 样式应用到 ajax 加载的 table
apply datatables.js style to table loaded by ajax
$(document).on('click', '.manage', function (event)
{
var userid = $(this).data('userid');
$.ajax(
{
type: "POST",
dataType:'html',
url:"../user/ajax/doclist.php",
async:true,
data:{userid:userid,task:'view'},
success:function(html)
{
$('.doclistdiv').html(html);
},
error:function(request,errorType,errorMessage)
{
alert ('error - '+errorType+'with message - '+errorMessage);
},
complete:function(html)
{
}
});
});
如上代码所示,我正在将 ajax 数据(作为 html)加载到我的页面。
在这些数据中,我 table.i 想要在加载后将 table 转换为 table 作为 table in datatable.js(www.datatables.net/)
我认为因为数据来自 html 服务器端处理不工作
在成功部分尝试以下操作:
var root = $('.doclistdiv');
root.html(html);
root.find('table').dataTable();
$(document).on('click', '.manage', function (event)
{
var userid = $(this).data('userid');
$.ajax(
{
type: "POST",
dataType:'html',
url:"../user/ajax/doclist.php",
async:true,
data:{userid:userid,task:'view'},
success:function(html)
{
$('.doclistdiv').html(html);
},
error:function(request,errorType,errorMessage)
{
alert ('error - '+errorType+'with message - '+errorMessage);
},
complete:function(html)
{
}
});
});
如上代码所示,我正在将 ajax 数据(作为 html)加载到我的页面。 在这些数据中,我 table.i 想要在加载后将 table 转换为 table 作为 table in datatable.js(www.datatables.net/)
我认为因为数据来自 html 服务器端处理不工作
在成功部分尝试以下操作:
var root = $('.doclistdiv');
root.html(html);
root.find('table').dataTable();