github.io阻止了ajax请求

时间:2016-07-18 09:26:23

标签: jquery ajax github-pages

我的所有带有ajax请求的应用都返回错误:此请求已被阻止;内容必须通过HTTPS提供。 例如: https://zzharuk.github.io/local_weather_widget/

function getWeather(location, value, callback) {
    var url = "http://api.openweathermap.org/data/2.5/weather";
    $.ajax({
        dataType: "jsonp",
        url: url,
        jsonCallback: 'jsonp',
        data: {
            appid:"3556435b983a95646ad9cab4a5ee0943",
            units: value,
            lat:location.latitude,
            lon:location.longitude
        },
        cache: false,
        success: function (data) {
            callback(data);
        }
    });
}
function LocalWeather() {
        $.ajax({
            url: '//freegeoip.net/json/',
            type: 'GET',
            dataType: 'jsonp',
            success: function (location) {
                getWeather(location,"metric",function (data) {
                    console.log(location);
                    console.log(data);
                 })
            }
        })
    }

2 个答案:

答案 0 :(得分:1)

通过阅读their prices list,您可以看到SSL仅适用于某些付费订阅者。

答案 1 :(得分:0)

所有它要求你做的是使用安全HTTP(HTTPS)而不是普通的,未加密的http。

所以只需从

更改您的网址即可
var url = "http://api.openweathermap.org/data/2.5/weather";

var url = "https://api.openweathermap.org/data/2.5/weather";