【发布时间】:2012-07-07 14:51:34
【问题描述】:
我在读取 JSON 数据时遇到问题。
model.php
class chatApp extends database{
public $row = array();
public function IO(){
//SELECTING FROM DATABASE MAKE QUERY ....
$this->row = $mysql->show; //result
return $this->row; //return it
}}
controller.php
if(isset($_GET['showmessage'])){
$chatApp = new chatApp(); // chat app object
$row = $chatApp->IO();
echo json_encode($row);} // echo it like json
view.php
function update(){
$.ajax({
type: "POST",
url: " http://localhost/chat/controller.php?showmessage",
dataType: 'json',
success: function(data) {
$("#chat").html(data); //The data ?
}
});
} setInterval (update, 1000);
所以问题是我无法在聊天 div 中显示数据?我做错了什么
【问题讨论】:
-
当您在浏览器中访问controller.php 时会发生什么?您是否看到任何 JSON 输出?
-
你是如何在你的 javascript 中调用 update() 函数的?
-
@TomWalters 是的,我看到了 JSON:[{"id":"1","message":"sdvsvdsdv","nickname":""}]
-
@Austin setInterval(更新,1000);