我的问题很简单,我有一个名为new.json的文件,我试图使用JQuery来加载和显示数据。我一直在写JavaScript代码:
$.getJSON("new.json", function(data){
// I have placed alert here previously and realized it doesn't go into here
$.each(data.streetCity, function(i,s){
alert(s);
});
});
}
和new.json数据看起来如下:
{"streetCity":
{
"1":"Abergement-Clemenciat",
"2":"Abergement-de-Varey",
"3":"Amareins"
}
};
确保'new.json'与运行生成ajax请求的JS的文件位于同一目录中。我很肯定你也不想要'''。 –
如果没有在本地机器上运行服务器,某些浏览器将不会允许Ajax无需调整设置 – charlietfl
如果您使用Chrome,可能会出现重复问题:http://stackoverflow.com/questions/2541949/problems-with-jquery-getjson-使用本地文件在chrome – apsillers