2016-08-12 35 views
0

今天我在Firefox中发现的错误为什么阻止加载混合活动内容?

Blocked loading mixed active content "http://ip-api.com/json/?callback=jQuery2240797948164524662_1471014635124&_=1471014635125"

这里是我的代码

function getCurrentWeather(){ 
    $.getJSON("http://ip-api.com/json/?callback=?", function(data) { 
     var lat=data["lat"]; 
     var lon=data["lon"]; 
     updateWeatherDisplay(lat,lon);   
     updateAddress(data["city"],", "+data["region"]); 
    }); 
} 

但这里是其它代码,使相当于查询到的API - 没有错误!:

function getLocation() { 
    $.get('http://ip-api.com/json', function(loc) { 
     $('#location').text(loc.city + ', ' + loc.region + ', ' + loc.country); 
     getWeather(loc.lat, loc.lon, loc.countryCode); 
    }) 
    .fail(function(err) { 
     getWeather(); 
    }); 
} 

两个实例运行在https://codepen IO。

我已经知道我应该使用https://来调用api。 但我很好奇,为什么第二个例子中没有错误?

+1

的可能的复制[为什么我突然得到一个“在Firefox阻止加载混合活动内容”问题?](http://stackoverflow.com/questions/18251128/why-am-i-suddenly-getting-a-blocked-loading-mixed-active-content-issue-in -fire) – Liam

+0

[因为从不受信任的第三方加载内容时存在安全漏洞](https://www.owasp.org/index.php/Cross- site_Scripting_(XSS)) – Liam

+0

我把这里的链​​接不在问题中。我的越野车示例 - https://codepen.io/pbweb/pen/GqGYag?editors=1010。和工作之一 - http://codepen.io/l-emi/pen/OXBwxL – kurumkan

回答

1

其因https://codepen/是使用安全HTTPS协议)和http://ip-api.com使用不安全(HTTP协议)。

ip-api.com目前还不支持HTTPS,如果支持HTTPS,你可以使用安全HTTPS协议https://ip-api.com

function getCurrentWeather(){ 
    $.getJSON("https://ip-api.com/json/?callback=?", function(data) { 
    var lat=data["lat"]; 
    var lon=data["lon"]; 
    updateWeatherDisplay(lat,lon);   
    updateAddress(data["city"],", "+data["region"]); 
    }); 
} 
相关问题