以下是我的PHP代码:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
include 'dbconnection.php';
try{
if (isset($_GET['term'])){
$return_arr = array();
$stmt = $conn->prepare('SELECT JOBNO FROM PRTJOBHD WHERE JOBNO LIKE :term');
$stmt->execute(array('term' => '%'.$_GET['term'].'%'));
while($row = $stmt->fetch()) {
$return_arr[] = $row['JOBNO'];
}
}
}catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
?>
我收到一条错误“Cross-Origin Request Blocked:同源策略禁止在http://192.168.0.102/ipack/search.php?term=a读取远程资源。(原因:CORS标题'Access-Control-Allow-Origin'丢失)。 “在浏览器上运行时。