Bonjour,

je ne parviens pas à remplir mon tableau via AJAX et JSON


le javascript issu de : https://datatables.net/examples/api/row_details.html,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
function format ( d ) {
    // `d` is the original data object for the row
    return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
        '<tr>'+
            '<td>Full name:</td>'+
            '<td>'+d.budget+'</td>'+
        '</tr>'+
        '<tr>'+
            '<td>Extension number:</td>'+
            '<td>'+d.projet+'</td>'+
        '</tr>'+
        '<tr>'+
            '<td>Extra info:</td>'+
            '<td>And any further details here (images etc)...</td>'+
        '</tr>'+
    '</table>';
}
 
$(document).ready(function() {
    var table = $('#table_id').DataTable( {
		"processing":  true,
		"serverSide": true,
		"ajax": {
			"url":"bdd.php",
			"dataType": "json",
			"type":"POST"
		},
        "columns": [
            {
                "className":      'details-control',
                "orderable":      false,
                "data":           null,
                "defaultContent": null
            },
            { "data": "site" },
            { "data": "commercial" },
            { "data": "produit" },
            { "data": "cible" }
        ],
        "order": [[1, 'asc']]
    } );
 
    // Add event listener for opening and closing details
    $('#table_id tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = table.row( tr );
 
        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child( format(row.data()) ).show();
            tr.addClass('shown');
        }
    } );
} );
ma requete php appelée par ajax
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
$request = 'SELECT * FROM informations WHERE site="bordeaux"'; 
$query = $db->prepare($request);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
$result2["data"] = json_encode($result);
echo json_encode($result2);

Mon problème est que mon tableau ne se remplit pas et m'affiche ce message :
DataTables warning: table id=table_id - Requested unknown parameter 'site' for row 0. For more information about this error, please see http://datatables.net/tn/4

la page ne m'a pas apporté grande aide ! toutes les données sont remplis dans ma db.

Une idée ?