Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/08/2018, 16:00
xoceunder
 
Fecha de Ingreso: junio-2012
Ubicación: En el Mundo
Mensajes: 759
Antigüedad: 11 años, 10 meses
Puntos: 10
Imprimir datos de json con jquery

Hola a todos es que ando tratando de imprimir datos de json


Este es mi Json
Código json:
Ver original
  1. {
  2.     "pets":[
  3.         { "animal":"dog", "name":"Fido" },
  4.         { "animal":"cat", "name":"Felix" },
  5.         { "animal":"hamster", "name":"Lightning" }
  6.     ]
  7. }

index.html

Código HTML:
Ver original
  1. <!DOCTYPE html>  
  2.  <html>  
  3.       <head>  
  4.            <title>Webslesson Tutorial | Load JSON Data using Ajax getJSON Method</title>  
  5.            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
  6.            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
  7.            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>  
  8.  <script>  
  9.  $(document).ready(function(){  
  10.       $("button").click(function(){  
  11.            $("table").show();  
  12.            $.getJSON("pets.json", function(data){  
  13.                 $.each(data, function(key, value){  
  14.                      $("table").append("<tr><td>"+value.name+"</td></tr>");  
  15.                 });  
  16.            });  
  17.       });  
  18.  });  
  19.  </script>  
  20.       </head>  
  21.       <body>  
  22.            <br />  
  23.            <div class="container" style="width:600px;">  
  24.                 <h3 align="">Load JSON Data using Ajax getJSON Method</h3><br />  
  25.                 <button class="btn btn-info">Load name List JSON Data</button>  
  26.                 <table class="table table-bordered" style="display:none;">  
  27.                      <tr>  
  28.                           <th>name Title</th>  
  29.                      </tr>  
  30.                 </table>  
  31.            </div>  
  32.            <br />  
  33.       </body>  
  34.  </html>