我正在尝试从存储在000webhost上的mySQL数据库中获取一些数据,Ionic向我显示了该错误消息:

我读到我需要启用CORS策略,但不知道应该在哪里启用。这是fetch_data.php代码:
<?php
require 'config.php';
$query = "SELECT lat, lng FROM gps WHERE id = (SELECT MAX(ID) FROM gps)";
$result = mysqli_query($con, $query);
if($result === FALSE) {
printf("Error: %s\n", mysqli_error($con));
}
$response = array();
while($row = mysqli_fetch_array($result)){
array_push($response, array(“lat”=>$row[0],“lng”=>$row[1]));
}
echo json_encode(array($response));
?>发布于 2021-08-05 05:37:48
添加到index.php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, PUT, OPTIONS, PATCH, DELETE');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Authorization, Content-Type, x-xsrf-token, x_csrftoken, Cache-Control, X-Requested-With');https://stackoverflow.com/questions/68655030
复制相似问题