Here is an array in php
$content = array('time' => $time, 'user' => $user, 'message' => $message); If the AJAX request for this page is successful, then in the file with php output
print_r($content); AJAX:
$(document).ready(function(){ $('#submit').click(function(){ var text = $('#text').val(); $.ajax({ type : 'POST', url : 'php/chat_script.php', data : { message:text }, success: function(arr) { arr = JSON.parse(arr); $('#time').html(arr.time); $('#user').html(arr.user); $('#message').html(arr.message); } }); }); }); For example, I need to output this into a HTML table like this: time at <td id="time"></td> , user at <td id="time"></td> and message at <td id="message"></td> How to do this?
The array has the form:
Array ( [0] => Array ( [time] => 16:20:11 [user] => qwe [message] => qwe ) )