javascript - 调用百度地图api,chrome显示连接不安全,请求被禁止,需要https,怎样解决
PHP中文网
PHP中文网 2017-04-11 13:01:33
0
2
472

本人调用了百度地图的API接口,在Firefox本地可以测试成功,而chrome失败,怎么回事,而将页面上传到github-pages中显示,在firefox设置解除保护,可以正常显示,但在chrome却不能显示,控制台信息如下:

4 Mixed Content: The page at 'https://lchreal6.github.io/fc...' was loaded over HTTPS, but requested an insecure script 'http://api.map.baidu.com/geoc...…3338585&location=23.0444612,113.3882067&output=json&pois=1&_=1474943338586'. This request has been blocked; the content must be served over HTTPS.

调用接口代码如下

$.getJSON('http://api.map.baidu.com/geocoder/v2/?ak=0FuoX30MFf7YMrdS5Wi9GGAcHBblKDuu&callback=?&location='+latitude+','+longitude+'&output=json&pois=1', function(res){
       
        $("#location").html(res.result.addressComponent.city);
        yourCurCity = res.result.addressComponent.city;
       
       
       
        

});

该怎样解决才能在chrome上正常显示。

PHP中文网
PHP中文网

认证0级讲师

Antworte allen(2)
伊谢尔伦

目测问题应该是你自己的网站是https协议,而请求的目标接口是http协议,所以会出现这个问题。

哈哈,打个广告,我自己写了个天气接口,不过只能查询国内的(https协议,支持GET/POST):
点我查询北京的天气

具体用法看这里-wiki

迷茫

你自己的页面所放的服务器应该是https的,这样你里面的请求也得是https的。
百度地图的话,你可以直接把http换成https,然后后面加上s=1。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!