Access-Control-Allow-Origin 不允许来源 http://localhost:xxxx

Origin http://localhost:xxxx is not allowed by Access-Control-Allow-Origin

我正在尝试从存储在 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));
?>

添加到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');