将json从php返回到Ajax调用

Using PHP script I am able get JSON. I am trying to return the JSON back using PHP script but I'm getting a 404 error when I try to receive it via AJAX. I am using this with Flask. Can someone explain what I am doing wrong?

PHP query

<?php
    $db = new SQLite3('example.db');

    $results = $db->query('SELECT * FROM things');
    while ($row = $results->fetchArray(SQLITE3_ASSOC)) {

    $jsonArray[] = $row;
    }

    json_encode($jsonArray)
?>

AJAX

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$.ajax({
            url: 'query.php',
            dataType: "json", //if it returns a xml file
            success: function (data) {
                // everything is ok
                alert(data)

            },
            error: function (xhr, status, error) {
                // Something went wrong
                if (xhr.status > 0) alert('Error: ' + status)
                    console.log("error something went wrong");
            }
        });
</script>