[Solved] Ajax post returns multiple arrays with objects that have multiple values


Your ajax.php should be like this

<?php


  foreach ($messages as $message) {
    $from = $message['contact_value'];
    $text = $message['message'];
    $date = $message['date'];
    $num = $user['phone_number'];
    echo json_encode(array("from"=>$from, "text"=>$text,"date"=>$date,"num"=>$num));
?>

if you really want the quotes then use ‘ ‘ (singlequotes) instead.

And the javascript file.

 success: function (response) {
  var success = $.parseJSON(response);
  $(".messages-table").append("<tr><th>"+success.from+"</th><th>"+success.text+"</th><th>"+success.date+"</th><th>"+success.num+"</th></tr>");
}

i think you don’t need to use the forech loop if you call the doAjax function every time.

solved Ajax post returns multiple arrays with objects that have multiple values