C# 如何在此Javascript中添加jQuery DataTable
是否可以添加以下jQuery数据表C# 如何在此Javascript中添加jQuery DataTable,c#,asp.net-mvc-4,jquery-datatables,C#,Asp.net Mvc 4,Jquery Datatables,是否可以添加以下jQuery数据表 $('#myDataTable').dataTable({ }); 你对这个问题有何看法 $(document).on('click', '#PlayStatisticeight', function (e) { $.ajax({ url: '@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")', type: 'GET',
$('#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';
}
}
});
});
我不知道如何以及是否有可能这样做?非常感谢您的帮助:)是的,只要在成功回调函数中将新部分添加到DOM后调用它即可
success: function (data) {
$.ajax({
url: '@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")',
type: 'GET',
success: function (data) {
$("#PartialViewTopPlayedTracksList").empty();
$("#PartialViewTopPlayedTracksList").append(data);
});
},
在ajax call complete函数中将partialview附加到视图之后,可以初始化datatable,如下所示:
success: function (data) {
$.ajax({
url: '@Url.Action("_PartialViewTopPlayedTracksList", "ReportStatistic")',
type: 'GET',
success: function (data) {
$("#PartialViewTopPlayedTracksList").empty();
$("#PartialViewTopPlayedTracksList").append(data);
$('#myDataTable').dataTable({ });
});
}
这可能不起作用,因为在加载_PartialViewTopPlayedTracksList操作之前,不会有任何应用dataTable的内容。他需要为_partialviewtoplayedtrackslist执行$.get(),然后在成功函数中应用数据表。@Justin谢谢:)我尝试过,但它没有显示数据表,并且停止了其他查询。@Dave:谢谢:)-我怎么做?抱歉,我不太熟悉jQuery。@pv619,Dave发现了它,请参见上面我的更新,这将使用GET加载并附加结果。@JustinHarvey-感谢您花时间编辑代码。我已经用新代码更新了我的初始代码。所有查询现在都正常工作,但DataTable没有显示。谢谢:)它工作得很好,但在最终测试之后-查询停止了其他查询的工作。i、 e.我也在使用jTables。有什么建议吗?:)如果这些插件应用于动态呈现的部分视图html,那么在ajax调用成功后,您也需要初始化该插件