Javascript 请求到来时,Datatable无法刷新自身

Javascript 请求到来时,Datatable无法刷新自身,javascript,jquery,datatables,Javascript,Jquery,Datatables,弹出窗口中有一个datatable。当我试图使用ajax请求更改datatable中显示的值时,datatable值不会更改。我可以看到检索到的数据是正确的,但是这些数据没有显示datatable var isAjax = @isAjax; if(isAjax) { dataTables.taskList = $('#following').dataTable({ // the same initialization params used but left out

弹出窗口中有一个datatable。当我试图使用ajax请求更改datatable中显示的值时,datatable值不会更改。我可以看到检索到的数据是正确的,但是这些数据没有显示datatable

var isAjax = @isAjax;
if(isAjax)
{ 

    dataTables.taskList = $('#following').dataTable({
        // the same initialization params used but left out here for brevity
        dom: 'Bfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5'
        ],
        "bServerSide": true,
        "bRetrieve": true,
    });
    $(document).ready(function () {
        // Initialize the plugin
        $('#').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });


}
else
{
    $(new function () {
        $('#following').DataTable( {  
            dom: 'Bfrtip',
            buttons: [
                'excelHtml5',
                'csvHtml5'
            ],

        } );
    });        
    $(document).ready(function () {
        // Initialize the plugin
        $('#testfollowing').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });
}
代码如下:

<script>
function CreateChart() {
    var chart = AmCharts.makeChart("piechartdiv", {
        "type": "pie",
        "theme": "light",
        "fontFamily":"Calibri",


        "dataProvider": [{
            "product":"Following",
            "value": @following,
            "color": "#009688"
        }, {
            "product":"Not following",
            "value": @notFollowing,
            "color": "#555555"

        }],
        "legend": {
            "align" : "right",
            "fontSize" : 14
        },
        "marginLeft":-100,
        "marginTop":-45,
        "marginBottom":0,
        "labelsEnabled":false,
        "colorField": "color",
        "valueField": "value",
        "titleField": "product",
        "outlineAlpha": 0.4,
        "depth3D": 15,
        "balloonText": "[[title]]<br><span style='font-size:14px'><b>[[value]]</b> ([[percents]]%)</span>",
        "angle": 20,
        "export": {
            "enabled": true
        }
    });

    jQuery('.chart-input').off().on('input change', function () {
        var property = jQuery(this).data('property');
        var target = chart;
        var value = Number(this.value);
        chart.startDuration = 0;

        if (property == 'innerRadius') {
            value += "%";
        }

        target[property] = value;
        chart.validateNow();  
    });
    chart.addListener("clickSlice", function (event) {
        if ( event.dataItem.title == 'Unfollowing')
        {
            document.getElementById("s_open").click();
        }
    }); 
}
var isAjax = @isAjax;
if(isAjax)
{

    CreateChart();

}
else
{
    AmCharts.ready(function () {
        CreateChart();
    });
}
var isAjax = @isAjax;
if(isAjax)
{ 

    dataTables.taskList = $('#following').dataTable({
        // the same initialization params used but left out here for brevity
        dom: 'Bfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5'
        ],
        "bServerSide": true,
        "bRetrieve": true,
    });
    $(document).ready(function () {
        // Initialize the plugin
        $('#').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });


}
else
{
    $(new function () {
        $('#following').DataTable( {  
            dom: 'Bfrtip',
            buttons: [
                'excelHtml5',
                'csvHtml5'
            ],

        } );
    });        
    $(document).ready(function () {
        // Initialize the plugin
        $('#testfollowing').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });
}

var isAjax = @isAjax;
if(isAjax)
{ 

    dataTables.taskList = $('#following').dataTable({
        // the same initialization params used but left out here for brevity
        dom: 'Bfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5'
        ],
        "bServerSide": true,
        "bRetrieve": true,
    });
    $(document).ready(function () {
        // Initialize the plugin
        $('#').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });


}
else
{
    $(new function () {
        $('#following').DataTable( {  
            dom: 'Bfrtip',
            buttons: [
                'excelHtml5',
                'csvHtml5'
            ],

        } );
    });        
    $(document).ready(function () {
        // Initialize the plugin
        $('#testfollowing').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });
}

数据是通过Razor而不是Ajax提供的,只是Ajax的请求。如何解决此重新生成问题?

您在等待加载数据之前打开弹出窗口,尝试替换
$(文档)。准备好(function(){
$('#following')。在('xhr.dt',function(){
上,在收到数据时显示弹出窗口。在等待加载数据之前打开弹出窗口,尝试替换
$(document).ready(function(){
$('#following')。在('xhr.dt',function(){
上,接收数据时显示弹出窗口。
var isAjax = @isAjax;
if(isAjax)
{ 

    dataTables.taskList = $('#following').dataTable({
        // the same initialization params used but left out here for brevity
        dom: 'Bfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5'
        ],
        "bServerSide": true,
        "bRetrieve": true,
    });
    $(document).ready(function () {
        // Initialize the plugin
        $('#').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });


}
else
{
    $(new function () {
        $('#following').DataTable( {  
            dom: 'Bfrtip',
            buttons: [
                'excelHtml5',
                'csvHtml5'
            ],

        } );
    });        
    $(document).ready(function () {
        // Initialize the plugin
        $('#testfollowing').popup({
            color: 'black',
            opacity: 0.5,
            transition: '0.3s',
            scrolllock: true
        });
    });
}