【问题标题】:Prevent second ajax call on response防止第二次ajax调用响应
【发布时间】:2018-11-13 17:38:10
【问题描述】:

jquery 数据表中的 ajax 请求在服务器端处理中发出多个请求,而不是一次一个。该表在 document.ready() 上初始化。

一旦收到响应,我想中止 jquery 数据表中的 ajax 调用。

有没有办法在响应成功时停止第二次请求?

document.ready(function() {

        $("#myTable").DataTable({
        "processing": true, // for show progress bar
        "serverSide": true, // for process server side
        "orderMulti": false, // for disable multiple column at once
        "ajax": {
            "url": "/home/LoadData",
            "type": "Get",
            "datatype": "json"
            "data":{ date:'date'},// parameter on controller to filter records 
        },
        "columns": [
                { "data": "ContactName", "name": "ContactName", "autoWidth": true },
                { "data": "CompanyName", "name": "CompanyName", "autoWidth": true },
                { "data": "Phone", "name": "Phone", "autoWidth": true },
                { "data": "Country", "name": "Country", "autoWidth": true },
                { "data": "City", "name": "City", "autoWidth": true },
                { "data": "PostalCode", "name": "PostalCode", "autoWidth": true }
        ]
    });

【问题讨论】:

  • 显示您的代码。我们需要看看你尝试了什么。

标签: javascript jquery ajax datatables


【解决方案1】:

不看代码很难说,但如果你有事件对象的句柄,你可以执行类似 evt.preventDefault() 之类的操作来阻止发送默认表单提交。

【讨论】:

    【解决方案2】:

    https://datatables.net/manual/ajax

    https://m.datatables.net/forums/discussion/32107/how-to-load-an-array-of-json-objects-to-datatables

    您可以通过设置 column 属性来手动输入它

    $('#myTable').DataTable( {
        ajax: ...
    } );
    
    // or!
    
    $('#myTable').DataTable( {
        ajax: ...,
        columns: [
            { data: 0 },
            { data: 1 },
            { data: 2 },
            { data: 3 },
            { data: 4 },
            { data: 5 }
        ]
    } );
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多