douwen9343 2018-09-30 04:16
浏览 56

JSON:从另一个域中检索JSON文件

After awhile of not using JSON, I'm a little rusty on the possibility of requestiing the data from another domain/web-server.

<?php header('Access-Control-Allow-Origin: *');
  if(!empty($_GET['file'])){
?>
  jsonFile = 'data/<?php echo $_GET['file']; ?>';
<?php
  }
?>

Is there a way to do this without using JSONP? I think the way I have my code setup, it queries from a data/ folder. That data folder is also available on the other web server. Any thoughts? All appreciated.

  • 写回答

1条回答 默认 最新

  • dongzi0850 2018-09-30 04:25
    关注

    You don't need that header here. Presence of Access-Control-Allow-Origin matters only when you are requesting a resource from another domain via browser. And it's the target server that should return the header not the client. Since you are using PHP you just need to request the resource normally.

    Check the MDN's CORS article for more information.

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向