When I send an ajax post request to my getMessages.php file it doesn't return anything.
I've tried manually setting the array values and printing them in the console and that seems to work.
getMessages.php
<?php
require_once "mysqli.php";
$data = array();
if (isset($_POST['getChat']) && !empty($_POST['getChat'])) {
    $username = $_SESSION["username"];
    $result = mysqli_query($conn, "SELECT msg_startuser, msg, time 
        FROM messages 
        WHERE msg_startuser = '{$username}' and msg_enduser = 'mariokiller470' 
        UNION 
        SELECT msg_startuser, msg, time 
        From messages 
        WHERE msg_startuser = 'mariokiller470' and msg_enduser = '{$username}' 
        order by time;
    ");
    while ($row = mysqli_fetch_array($result)) {
        $data['startuser'] = $row['msg_startuser'];
        $data['msg'] = $row['msg'];
    }
}
echo json_encode($data);
exit;
?>
js ajax
function getChat() {
    $.ajax({
        url: 'getMessages.php',
        type: 'POST',
        data: {getChat: 'yes'},
        dataType: 'JSON',
        success: function(data) {
            // testing
            console.log(data.startuser, data.msg);
        }
    })
}
I want it to print out in the console for testing.
 
     
     
     
    