我目前正在从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