DataTable X Json

DataTable X Json

fmellobrasilfmellobrasil Posts: 1Questions: 1Answers: 0
edited March 2015 in Free community support

This is the return json I'm having .

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<string xmlns="http://tempuri.org/">
[{"id":"315","name":"PETRA10"},{"id":"316","name":"PETRA30"},{"id":"317","name":"PETRA32"},{"id":"318","name":"PETRA33"},{"id":"319","name":"PETRA34"},{"id":"320","name":"PETRA35"},{"id":"321","name":"PETRA36"},{"id":"322","name":"PETRA37"},{"id":"323","name":"PETRA40"},{"id":"324","name":"PETRA44"}]
</string>

but I can not integrate it with the DataTable bootstrap .

Below html / jquery

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <!-- DataTables CSS -->
    <link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.css">
  
    <!-- jQuery -->
    <script type="text/javascript" charset="utf8" src="//code.jquery.com/jquery-1.10.2.min.js"></script>
  
    <!-- DataTables -->
    <script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <table id="table_id" class="display">
            <thead>
                <tr>
                    <th>id</th>
                    <th>name</th>
                </tr>
            </thead>
        </table>
        <script type="text/javascript">
            $(document).ready(function () {
                $('#table_id').dataTable({
                    "processing": true,
                    "serverSide": true,
                    "ajax": {
                        "url": "teste.asmx",
                        "dataType": "TesteJson"
                    }
                });
            });
        </script>
    </form>
</body>
</html>

Will someone help me?

Thank you in advance
Fernando

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Hi Fernando,

    DataTables expects JSON data, but you are returning XML data (which just so happens that it contains JSON in the root element).

    The best fix is to simply return JSON if you can. Otherwise you need to use ajax.dataSrc to read the JSON out of the XML and return it.

    Allan

This discussion has been closed.