是否可以添加以下jQuery DataTable?
$('#myDataTable').dataTable({
});
这个查询?
$(document).on('click', '#PlayStatisticeight', function (e) {
$.ajax({
url: '@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")',
type: 'GET',
success: function (data) {
$("#PartialViewTopPlayedTracksList").empty();
$("#PartialViewTopPlayedTracksList").append(data);
$('#myDataTable').dataTable({
});
$(function () {
$("#PartialViewTopPlayedTracksList").load('@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")');
});
},
error: function (xhr, textStatus, exceptionThrown) {
var json = $.parseJSON(xhr.responseText);
if (json.Authenticated) {
window.location.href = '/UnAuthorizedUser/UnAuthorizedUser';
}
else {
window.location.href = '/UnAuthenticatedUser/UnAuthenticatedUser';
}
}
});
});
我不知道如何以及是否可以这样做?任何帮助都非常感谢:)
答案 0 :(得分:1)
是的,只需在成功回调函数中将新部分添加到DOM后调用它。
success: function (data) {
$.ajax({
url: '@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")',
type: 'GET',
success: function (data) {
$("#PartialViewTopPlayedTracksList").empty();
$("#PartialViewTopPlayedTracksList").append(data);
});
},
答案 1 :(得分:1)
你可以初始化datatable,在ajax调用完成函数的视图上附加了partialview后,如下所示:
success: function (data) {
$.ajax({
url: '@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")',
type: 'GET',
success: function (data) {
$("#PartialViewTopPlayedTracksList").empty();
$("#PartialViewTopPlayedTracksList").append(data);
$('#myDataTable').dataTable({ });
});
}