我在本地有一个angular的项目文件。
我在run运行块里面写了个$http:
app.run(function ($rootScope, $http) {
$http({
method: 'GET',
url: 'http://xxx/data/count.php',
params: { 'mode': 'nor' }
}).success(function (response) {
console.log(response)
})
});
然后一开始我在网上查询了一下失败的原因,在服务器的php接口文件上加上了header
header("Access-Control-Allow-Origin: *");
可是错误依然:
XMLHttpRequest cannot load http://xxx/data/count.php?mode=nor. Request header field Pragma is not allowed by Access-Control-Allow-Headers in preflight response.
请问如何才能让本地的angular代码能够获取到远端数据?
附上php接口文件代码:
$res];
echo json_encode($result);
//$result有内容
?>
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
headers : {