11484 sujets

JavaScript, DOM et API Web HTML5

Bonjour à tous,

Je débutes en Javascript et je cherche à afficher des données Json dans une balise HTML mais impossible d'y parvenir, pourriez-vous m'aider svp?

voici le code:

 <!doctype html>
<html class="no-js" lang="fr">
  <head>
    <meta charset="UTF-8">
    <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>Titre du document</title>
    <link rel="stylesheet" href="css/style.css" media="all">
        <link rel="stylesheet" href="css/bootstrap.min.css" media="all">


    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>

     <script src="js/data.js"></script>
  </head>
  <style>

  </style>
  <body>
  <div style="background-color: purple; height: 500px;" class="container">
  
  <div id="tb">CECI EST UN TEST</div>

  </div>

    <script>
        var tableHtml ="<table class='table table-stripped table-bordered table-hover'>";

        $.each(json, function (i) {
                tableHtml += "<tr>";
                tableHtml += "<td><button type='button' data-id=' "+ json[i].id +" 'class='btn btn-success' >Détails</button></td>";
                tableHtml += "<td>Commande n°" + json[i].id + "</td>";
                tableHtml += "<td>" + json [i].id + "</td>";
                tableHtml += "<td>" + json [i].nom + "</td>";
                tableHtml += "</tr>";
        });

        tableHtml += "</table>"

        $( "#tb" ).html( tableHtml );
    </script>
  </body>
</html>



Merci à tous pour votre aide!
Modifié par Herde35 (27 Nov 2017 - 13:10)