ajax - Problems reading json data with jquery (chat application) -
i have problem reading json data.
model.php
class chatapp extends database{ public $row = array(); public function io(){ //selecting database make query .... $this->row = $mysql->show; //result return $this->row; //return }} controller.php
if(isset($_get['showmessage'])){ $chatapp = new chatapp(); // chat app object $row = $chatapp->io(); echo json_encode($row);} // echo 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); so problem can't show data in chat div ? making wrong
try:
$("#chat").html(jquery.parsejson(data)); or use getjson instead of ajax:
function update(){ $.getjson("http://localhost/chat/controller.php?showmessage", function(data) { $("#chat").html(data); settimeout(update,1000); }); } settimeout(update,1000); use settimeout instead of setinterval
Comments
Post a Comment