我目前正在從php/javascript項目中檢索數據庫中的信息,並對json編碼數據進行編碼。它應該顯示網頁上組合框內數據庫的值。從Javascript獲取JSON數據
在編碼MySQL數據我有以下代碼PHP腳本:
$query = "SELECT pla_platformName as `platform` FROM platforms";
$result = mysql_query($query);
if ($result)
{
while ($myrow = mysql_fetch_array($result))
{
$output[] = $myrow;
}
print json_encode($output);
die();
}
在JavaScript代碼我有以下:
<script>
$(document).ready(function()
{
getPlatforms();
function getPlatforms()
{
$.post("phpHandler/get-platforms.php", function(json)
{
alert(json);
alert(json.platform);
}
);
}
});
</script>
我有警報(JSON);其中顯示瞭如下所示的整個json數據:
[{「0」:「hello」,「platform」:「hello」},{「0」:「android」,「platform」 「world」}]
下一個警報(json.platform)我期待它顯示hello或world或兩者,但在這一行上,它一直說未定義。爲什麼這不起作用,我如何獲得特定的平臺,即無論是你好,還是世界。
感謝您提供的任何幫助。
感謝您的幫助,但它仍然顯示,而我打字說出來.. :)希望它可以讓你你要去哪裏不確定 – Boardy
喔..別人貼。 :) – Mithon