我有一个 ajax 调用,它正在加载一个生成这个 json 输出的 php 文件:
{
"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"]
}
然后我使用以下 javascript 代码处理它:
$.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");
}
});
我的问题是成功功能中的两个警报功能都没有出现。我设置javascript对象的方式可能存在某种错误:路由也包含一个数组..