doufu5521 2017-05-01 09:22
浏览 38
已采纳

使用CORS但没有任何帮助我

I really researche for hours, but did not find any solution yet. I would like to get some data from a different server via jQuery and ajax. I get this error message in my chrome console:

XMLHttpRequest cannot load https://editeddomain.com//somedata.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. The response had HTTP status code 401.

This is my set up:

  • PHPStorm 2016.1
  • jQuery v3.2.1
  • Google Chrome
  • Fedora 25

This is what I already tried and I still get the same error:

  • <?php header('Access-Control-Allow-Origin: *'); ?>
  • Started Chrome with --disable-web-security
  • Installed the Chrome Extension Allow-Control-Allow-Origin: *
  • Installed the Chrome Extension JetBrains IDE Support and added like JetBrains recommended http://*/*

So none of those helped me and I am still seeing the error message.

PS: This tool is only for me, so that's why it is not and never will be installed on a different webserver than my PHPStorm environment

  • 写回答

3条回答 默认 最新

  • duanfenhui5511 2017-05-01 09:32
    关注

    For chrome, add another parameter in addition to --disable-web-security:

    --user-data-dir

    This was introduced at a later stage by Google.

    Also, for this to work, make sure you close ALL instances of Chrome, and then open the one with the parameters in it. And it will only work with the first tab opened there. It will have a yellow bar stating you're using an insecure tab.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)