I have an ajax call that is loading a php file that generates this json output:
{
"Pittsburg\/Bay Point - SFIA\/Millbrae": ["PITT", "NCON", "CONC", "PHIL", "WCRK", "LAFY", "ORIN", "ROCK", "MCAR", "19TH", "12TH", "WOAK", "EMBR", "MONT", "POWL", "CIVC", "16TH", "24TH", "GLEN", "BALB", "DALY", "COLM", "SSAN", "SBRN", "SFIA", "MLBR"],
"Millbrae\/SFIA - Pittsburg\/Bay Point": ["MLBR", "SFIA", "SBRN", "SSAN", "COLM", "DALY", "BALB", "GLEN", "24TH", "16TH", "CIVC", "POWL", "MONT", "EMBR", "WOAK", "12TH", "19TH", "MCAR", "ROCK", "ORIN", "LAFY", "WCRK", "PHIL", "CONC", "NCON", "PITT"]
}
I then process this with the following javascript code:
$.ajax({
url: "build-routes.php",
dataType: 'json',
success: function(routesAndStations){
var i;
for (var name in routesAndStations){ // this gets the route names
routes[name] = new array();
i = 0;
// this gets all the stations for each route
for(var station in routesAndStations[name]){
routes.name[i] = routesAndStations[name][station];
alert(routes.name[i]);
++i;
}
}
for(var name in routes){
var str = "";
str += name + ": "+routes.name[1];
alert(str);
}
},
error: function(){
alert("fail");
}
});
My problem is that both alert functions in the success function don't appear. There is probably some kind of mistake in the way I set up the javascript object: routes which also holds an array..