我對於新手,這樣下去容易:JSON數據對象不會追加
我想不通爲什麼這個$就功能將不是我的XHR數據追加到正確的位置。
// gets the cache data from our php file
function getcaches() {
$.ajax({
method: 'get',
url: "php/findcache.php",
dataType: "json", // return type data is json
success: function(data){ // <-- data is in json format
//parse the json data
$('#caches').append($('<p>' + data[0].name + '</p>'));
},
error: function(data) {
console.log('error');
}
});
return false;
}
這就是相關的javascript。我知道數據被正確地存儲在對象,因爲我可以看到螢火蟲吧...
[OU0397] => stdClass Object
(
[code] => OU0397
[name] => A Mighty Oak in the Open
[location] => 28.527633|-81.125167
[type] => Virtual
[status] => Available
)
我只是不明白我在做什麼錯。任何指針?
你爲什麼認爲你有'[0]'? – 2012-04-24 01:49:56
它是數據[0] .name還是data.name? – 2012-04-24 01:50:14
我已經試過了,既不給我回應 – pizoelectric 2012-04-24 01:57:11