在THIS页面上,我列出了一些虚拟地产和硬编码,每个地区都有一个跨度(文本“VEZI TELEFON”),当点击时显示电话号码。我想从一个JSON检索的每个电话号码(或PHP)的文件名为telefoane.json具有内容:使用json文件中的数据填充span标签
{
"telefoane":[{
"id":"1",
"tel":"0743127315"
},
{
"id":"2",
"tel":"072245875"
},
{
"id":"3",
"tel":"0756129458"
},
{
"id":"4",
"tel":"0725127216"
},
{
"id":"5",
"tel":"0723127322"
}]
}
我的代码,即可以看到下面不输出期望的结果:
$.ajax({
url: 'telefoane.json',
dataType: 'json',
success: function(data){
$.each(data, function(key, val){
console.log(key + ":" + val);
});
}
});
输出,不幸的是:
telefoane:[object Object],[object Object],[object Object],[object Object],[object Object]
我在做什么错?谢谢!
编辑:
$.ajax({
url: 'telefoane.json',
dataType: 'json',
success: function(){
$.each(data.telefoane, function() {
console.log(this.id + ": " + this.tel);
});
}
});