我是一個新手,我堅持檢索JSON數據。無法檢索JSON數據使用jQuery
以下是我的index.php:
<script type="text/javascript" src="jquery-1.3.2.min_2.js">
$("document").ready(function() {
$.getJSON("data.php",function(jsondata){
$("#content").html(jsondata[0].content);
});
});
</script>
</head>
<body>
<div id="content"></div>
<div class="lg"></div>
</body>
在我data.php我使用的編碼標準的方式發送數據:
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$row = mysql_fetch_row($result);
$jsonserver[$i] = $row;
}
echo json_encode($jsonserver);
header('Content-type: application/json');
mysql_free_result($result);
// close connection
mysql_close($con);
我使用MySQL數據庫。 當我打開本地主機/ data.php JSON數據顯示在瀏覽器上。 但如果我打開本地主機/ index.php我不能得到任何所需的輸出。 請解釋。 謝謝!
什麼'json_encode($ jsondata)'o本安輸出? – seriousdev 2011-03-09 23:33:50
這是'index.php'的完整代碼嗎?你有'id =「content」'元素嗎? – Xint0 2011-03-09 23:36:24
**未捕獲的ReferenceError:清單沒有定義**這是我在chrome中得到的錯誤_on按ctrl + shift + i_當我執行data.php時,但是firebug在firefox中並沒有顯示這種類型的東西。 – whatf 2011-03-09 23:50:40