Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h1>EXERCICE 3 : JSON </h1>
- <button type ="button" onclick="GenererFichier()">FichierJSON</button>
- <button type ="button" onclick="recup()">NuageJSON</button>
- <h5 id="ptest4"> </h5>
- <h5 id="resultat"> </h5>
- <script type="text/javascript">
- function GenererFichier(){
- $.getJSON( "fichier.json", function(data) {
- $('#ptest4').append("<ul>");
- $.each( data.employees, function(i,item) {
- $('#ptest4').append("<li>" + item.firstName + " " +item.lastName+ "</li>");
- });
- $('#ptest4').append("</ul>");
- });
- }
- function recup(){
- $.getJSON("nuages.json", function(data){readData(data);});
- }
- function readData(doc){
- var res = "<table><tr><th> Nom </th><th>Especes</th><th>Altitude min</th><th>Altitude max</th></tr>";
- $.each(doc.nuages.nuage, function(i,item){
- res +="<tr><td>"+item.nom+"</td><td>"+
- liste(item.especes)+"</td><td>"+
- item.altitude.min+"</td><td>"+
- item.altitude.max+"</td></tr>";
- });
- res +="</table>";
- $("#resultat").html(res);
- }
- function liste(data){
- var res = "<ul>";
- $.each(data.espece, function(i,item){
- res +="<li>"+item+"</li>";});
- res+="</ul>";
- return res;
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement