<head> <meta charset="utf-8"/> <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css"> <script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#table_aliments').DataTable(); } ); </script> <script type="text/javascript"> $(document).ready( function() { $.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php', function(json){ // console.log(json); table = $('#tbody_aliment'); table.html(''); // cf. https://api.jquery.com/jQuery.getJSON/ $.each( json, function( key, val ) { table.append('<tr><td>'+val[1]+'</td><td>'+val[2]+'</td></tr>'); }); } ); // $.getJSON('https://eden.imt-lille-douai.fr/~charlotte.raulin/Projet/api/afficher_aliments.php', // function(json){ // $.('#tbody_aliment').html(''); // for (let i = 1; i < json.lenght; i++){ // $('#tbody_aliment').append('<tr><td>'json[i][1]+'</td><td>'+json[i][2]+'</td></tr>'); // } // }; // ); }); </script> </head> <section id="aliments_contenu" style="display : flex; flex-direction : row; "> <div style="margin-right:100px"> <table id="table_aliments" class="dataTable" style="color : #212529; "> <thead> <tr> <th>Aliment</th> <th>Type</th> <th>AjoutAuJournal</th> </tr> </thead> <tbody id="tbody_aliment"><tbody> </table> </div> <div> <table> <tr> <td> <form id="form_aliment" action="api/ajouter_aliment.php" method="POST" > <div> <label>Aliment</label> <input type="text" id="aliment" name="aliment" required> </div> <div> <label>Type d'aliment </label> <input type="text" id="cat" name="cat" required> <!-- <select id="type" size="1"> <option value="fruit"> Fruit </option> <option value="legume"> Legume </option> </select> --> </div> <div class="form-action-buttons"> <input type="submit" value="Ajouter"> </div> </form> </td> </tr> </table> </div> </section>