使用PHP脚本,我可以获取JSON。我正在尝试使用PHP脚本返回JSON,但是当我尝试通过AJAX接收JSON时却遇到404错误。我在Flask上使用它。有人可以解释我在做什么错吗?
PHP查询
<?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>