Hola a todos es que ando tratando de imprimir datos de json
Este es mi Json
Código json:
Ver original{
"pets":[
{ "animal":"dog", "name":"Fido" },
{ "animal":"cat", "name":"Felix" },
{ "animal":"hamster", "name":"Lightning" }
]
}
index.html
Código HTML:
Ver original<!DOCTYPE html>
<title>Webslesson Tutorial | Load JSON Data using Ajax getJSON Method
</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> $(document).ready(function(){
$("button").click(function(){
$("table").show();
$.getJSON("pets.json", function(data){
$.each(data, function(key, value){
$("table").append("
<tr><td>"+value.name+"
</td></tr>");
});
});
});
});
<div class="container" style="width:600px;"> <h3 align="">Load JSON Data using Ajax getJSON Method
</h3><br /> <button class="btn btn-info">Load name List JSON Data
</button> <table class="table table-bordered" style="display:none;">