Advertisement
darkmavis1980

Untitled

Nov 26th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  2.     <script>
  3.         $( document ).ready(function() {
  4.         var url="app/calciatori.json";
  5.         var por=[];
  6.         var dif=[];
  7.         var cen=[];
  8.         var att=[];
  9.         console.log(por[0]);
  10.         $.getJSON(url) //chiamata al file json
  11.         .done(function(data){ // se va a buon fine
  12.           $.each(data,function(i){ //ciclo sull'array
  13.             switch (data[i].ruolo) {
  14.             case "por": por.push(data[i].nome); break; //li metto nell'array
  15.             case "dif": dif.push(data[i].nome); break;//li metto nell'array
  16.             case "cen": cen.push(data[i].nome); break;//li metto nell'array
  17.             case "att": att.push(data[i].nome); break;//li metto nell'array
  18.             default: //do anything
  19.           }
  20.             });
  21.           //debug nella consolle
  22.             console.log(por[0]);
  23.             console.log(dif);
  24.             console.log(cen);
  25.             console.log(att);
  26.         giveMeTheGoalkeeper();
  27.         }) //se fallisce la chiamata json stampo l'errore
  28.         .fail(function( jqxhr, textStatus, error ) {
  29.             var err = textStatus + ", " + error;
  30.             console.log( "Request Failed: " + err );
  31.         });
  32.        
  33.     function giveMeTheGoalkeeper(){
  34.       console.log(por[0]);
  35.     }
  36.     });
  37.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement