Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
- <script>
- $( document ).ready(function() {
- var url="app/calciatori.json";
- var por=[];
- var dif=[];
- var cen=[];
- var att=[];
- console.log(por[0]);
- $.getJSON(url) //chiamata al file json
- .done(function(data){ // se va a buon fine
- $.each(data,function(i){ //ciclo sull'array
- switch (data[i].ruolo) {
- case "por": por.push(data[i].nome); break; //li metto nell'array
- case "dif": dif.push(data[i].nome); break;//li metto nell'array
- case "cen": cen.push(data[i].nome); break;//li metto nell'array
- case "att": att.push(data[i].nome); break;//li metto nell'array
- default: //do anything
- }
- });
- //debug nella consolle
- console.log(por[0]);
- console.log(dif);
- console.log(cen);
- console.log(att);
- giveMeTheGoalkeeper();
- }) //se fallisce la chiamata json stampo l'errore
- .fail(function( jqxhr, textStatus, error ) {
- var err = textStatus + ", " + error;
- console.log( "Request Failed: " + err );
- });
- function giveMeTheGoalkeeper(){
- console.log(por[0]);
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement