dos8244 2017-04-03 17:06
浏览 282

如何解决ERROR No'Access-Control-Allow-Origin'

I use a AJAX-Jquery post to calculate the time to get from A to B using Google API.

But i get the error "XMLHttpRequest cannot load https://maps.googleapis.com/maps/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."

I've read a lot of posts and tried several solutions. None of them worked.

  1. with different variants of headers in my .php page

    header("Access-Control-Allow-Origin", "*");
    header('Access-Control-Allow-Credentials: true');
    
  2. modifing my .htaccess file:

    Header set Access-Control-Allow-Origin "*"
    
  3. installing Chrome extension Allow-Control-Allow-Origin

The third choise allowed me to test my code but is not a real solution. Does anyone succeded to solve this?

  • 写回答

1条回答 默认 最新

  • duan198409 2017-04-03 17:09
    关注

    What you're going to need is

    JSONP

    JSONP or "JSON with padding" is a communication technique used in JavaScript programs running in web browsers to request data from a server in a different domain, something prohibited by typical web browsers because of the same-origin policy.

    Somewhere inside your AJAX call, you're going to make sure that the dataSet is jsonp.

    评论

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂