简体   繁体   English

DataTables警告:table id = example - 无效的JSON响应

[英]DataTables warning: table id=example - Invalid JSON response

I have googled for the answer of this question but noone helped. 我搜索了这个问题的答案,但没有人帮忙。 I am getting error mentioned in title. 我在标题中提到了错误。

Here is my ajax code : 这是我的ajax代码:

var table = $('#example').DataTable( {
        "ajax": "<?php echo $root; ?>ajax/order.php",
        "processing": true,
        "serverSide": true,
        "ordering": false,
        "searching": true,
        "columns": [
            { "data": "order_no" },
            { "data": "country" },
            { "data": "name" },
            { "data": "date","className": "align-center" },
            { "data": "subtotal","className": "align-right" },
            { "data": "dileveryAmt","className": "align-right" },
            { "data": "totalAmt","className": "align-right" },
            { "data": "paymentMode","className": "align-center" },
            { "data": "payment","className": "align-center" },
            { "data": null,"defaultContent": "<button id='view' class='btn btn-small btn-info'>View</button><button id='delete' class='btn btn-small btn-danger'>Delete</button>","className": "align-center" }
        ]
    } )

I validated Response from server ( as seen in Developer tools) and its being shown as Valid JSON. 我验证了来自服务器的响应(如开发人员工具中所示),并显示为有效JSON。 But its not reflected in page. 但它没有反映在页面中。

My HTML Code is 我的HTML代码是

<table id="example" class="display table-bordered" cellspacing="0" width="100%">
<thead>
    <tr>
        <th>Order No</th>
        <th>Country</th>
        <th>Customer</th>
        <th>Date</th>
        <th>Sub Total</th>
        <th>Delivery Charge</th>
        <th>Total</th>  
        <th>Payment Mode</th>
        <th>Payment</th>
        <th>Action</th>            
    </tr>
</thead>

UPDATE UPDATE

Response from Server(there are plenty of entries. I am showing one as example): 来自服务器的响应(有很多条目。我以一个例子显示):

"data": [
    {
        "id": "183",
        "customer_id": "183",
        "subtotal": "0.00",
        "totalAmt": "0.00",
        "dileveryAmt": "0.00",
        "date": "18/02/2015",
        "midnightdelivery": "0",
        "delivery_date": "2015-02-19",
        "message_on_cake": "",
        "special_instruction": "",
        "payment": "<div class='label label-warning'>Pending</div>",
        "delivery": "0",
        "created": "2015-02-18 10:58:29",
        "ip": "",
        "payment_mode": "",
        "first_name": "Ganesh",
        "last_name": "Salunkhe",
        "email": "g@s.com",
        "address": "",
        "flat_no": "k",
        "building_name": "k",
        "street": "k",
        "area": "k",
        "landmark": "k",
        "city": "mumbai",
        "country": "India",
        "state": "maharashtra",
        "contact_no": "7666902899",
        "name": "Ganesh Salunkhe",
        "order_no": "1181"
    },

Any help will be appreciated. 任何帮助将不胜感激。

I struggled with this. 我为此苦苦挣扎。 and after I RTM here https://www.datatables.net/examples/ajax/custom_data_flat.html I figured it out. 在我RTM之后https://www.datatables.net/examples/ajax/custom_data_flat.html我明白了。

 ajax: {
        url: "data/objects_root_array.txt", <-- notice url and the link
        dataSrc: "" <-- if you are just going to json_encode the result from the db. it will handle a flat string
    }

ajax calls are done a certain way. ajax调用是以某种方式完成的。 not just ajax. 不仅仅是ajax。 but you need to include the url and dataSrc variables in there. 但是你需要在那里包含url和dataSrc变量。 After I did that with my code everything worked as it should. 在我用我的代码完成后,一切正常。

See if this works for you. 看看这是否适合你。

var table = $('#example').DataTable( {
    "ajax": {
        url: "<?php echo $root; ?>ajax/order.php",
        dataSrc : ""
    },
    "processing": true,
    "serverSide": true,
    "ordering": false,
    "searching": true,
    "columns": [
        { "data": "order_no" },
        { "data": "country" },
        { "data": "name" },
        { "data": "date","className": "align-center" },
        { "data": "subtotal","className": "align-right" },
        { "data": "dileveryAmt","className": "align-right" },
        { "data": "totalAmt","className": "align-right" },
        { "data": "paymentMode","className": "align-center" },
        { "data": "payment","className": "align-center" },
        { "data": null,"defaultContent": "<button id='view' class='btn btn-small btn-info'>View</button><button id='delete' class='btn btn-small btn-danger'>Delete</button>","className": "align-center" }
    ]
} )

Think the problem is paymentMode . 认为问题是paymentMode It is written without underscore in the table definition and with underscore in your json ( "payment_mode": ) 它在表定义中没有下划线,在json中使用下划线( "payment_mode":

The answer should look like this: 答案应如下所示:

{
    "data": [
    {
        "id": "183",
        "customer_id": "183",
        "subtotal": "0.00",
        "totalAmt": "0.00",
        "dileveryAmt": "0.00",
        "date": "18/02/2015",
        "midnightdelivery": "0",
        "delivery_date": "2015-02-19",
        "message_on_cake": "",
        "special_instruction": "",
        "payment": "<div class='label label-warning'>Pending</div>",
        "delivery": "0",
        "created": "2015-02-18 10:58:29",
        "ip": "",
        "payment_mode": "",
        "first_name": "Ganesh",
        "last_name": "Salunkhe",
        "email": "g@s.com",
        "address": "",
        "flat_no": "k",
        "building_name": "k",
        "street": "k",
        "area": "k",
        "landmark": "k",
        "city": "mumbai",
        "country": "India",
        "state": "maharashtra",
        "contact_no": "7666902899",
        "name": "Ganesh Salunkhe",
        "order_no": "1181"
    }
] 
}

Look at here: http://json.parser.online.fr/ 请看这里: http//json.parser.online.fr/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据表警告表 id=datatables-example - 无效的 json 响应 - Datatables warning table id=datatables-example - invalid json response php DataTables中的Ajax警告:表格ID = example-无效的JSON响应 - Ajax from php DataTables warning:table id=example - Invalid JSON response DataTables警告:表格ID = {id}-无效的JSON响应 - DataTables warning: table id={id} - Invalid JSON response DataTables警告:表格ID = staff_data-无效的JSON响应 - DataTables warning: table id=staff_data - Invalid JSON response DataTables 警告:表 - 无效的 JSON 响应 - DataTables warning: table - Invalid JSON response DataTables 警告:表 id=tbl - 无效的 JSON 响应。 关于这个错误,请参阅 http://datatables.net/tn/1 - DataTables warning: table id=tbl - Invalid JSON response. about this error, please see http://datatables.net/tn/1 数据表警告:表 id=table_companies - JSON 响应无效。 有关此错误的更多信息,请参阅 http://datatables.net/tn/1 - DataTables warning: table id=table_companies - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1 数据表警告:表 id=users_list - JSON 响应无效。 有关此错误的更多信息,请参阅 http://datatables.net/tn/1 - DataTables warning: table id=users_list - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1 数据表,数据库服务器端处理和“数据表警告(表ID =&#39;示例&#39;)” - DataTables, database serverside processing and “DataTables warning (table id = 'example')” “数据表警告:无效的JSON响应”和“错误:找不到图容器元素” - “DataTables warning: Invalid JSON response” and “Error: Graph container element not found”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM