我正在try 使用FETCH从另一台服务器获取JSON文件:
fetch('https://site.test/data.json',
{
method: "GET",
})
.then(function (res) {
return res.json();
})
.then(function (data) {
console.log(data);
});
如果我直接取,我会收到CORS问题.
如果我通过PHP获取,我没有CORS问题,但我没有得到文件本身,所以它不能被缓存.
header('Access-Control-Allow-Origin: *');
echo file_get_contents("data.json");
有没有可能以某种方式返回文件本身,并在php中设置理想的缓存头?