我試圖訪問一個jQuery JSON對象,我看不出什麼毛病witj我的代碼JSON對象,但我得到的,當我嘗試訪問的對象是undefined
,我在想,也許這是因爲它是嵌套的方式,但我不確定,這裏是我的代碼,Acessing使用jQuery
function systems(dom_id, id){
$.getJSON("get_systems.php", {uid:id}, function(data){
// here I get the general system info related to the user
$.each(data, function(i, json){
//here I get each systems name, related to each system
$.getJSON('get_system_name.php', {uid:json.product_id}, function(data){
console.log(data.products);
$(dom_id).append('<tr><th>'+data.products+'</th></tr>');
});
});
});
};
列名與系統中它的名字,被命名爲products
,因此我嘗試使用,以獲取名稱data.products
,但我得到的是undefined
正如我上面提到。
但當我只要登錄data
它顯示的對象,它看起來像這樣,[Object { products="this is the product name"}]
,這是我用它來獲得系統名稱PHP,
get_system_name.php:
<?php
$uid = $_GET['uid'];
mysql_connect("localhost", "user", "1234") or die(mysql_error());
mysql_select_db("the_DB") or die(mysql_error());
$query = mysql_query("SELECT products FROM products WHERE product_id='$uid'") or die(mysql_error());
while($array = mysql_fetch_array($query, true)) {
$string[] = $array;
}
$json = json_encode($string);
echo $json;
?>
感謝提前!
有沒有這樣的事,作爲一個「JSON對象」。它可以是JSON字符串,也可以是本機對象。 – 2010-10-20 08:19:29
編輯問題以添加json輸出(通過直接訪問瀏覽器中的url) – 2010-10-20 08:26:00
Thanx,對於所有這些仍然是新東西,所以請原諒我的無知,但感謝您的更正,請問我可以在哪裏學習更多關於這個問題? – Odyss3us 2010-10-20 08:32:28