0
我有一個項目完成了,當您在Github頁面上上傳它時,它不起作用。它不會引入任何腳本,外部鏈接的字體和API數據。 API僅支持HTTP,而Github頁面只接受HTTPS。任何方式在不改變API的情況下繞過它? 該API是Openweathermap。Githubmap上的Openweathermap API
$(document).ready(function(){
var temp = $('.temperature');
var APIKEY = ';
var loc = $('#search').val();
function updateByCity(loc){
\t var url = "http://api.openweathermap.org/data/2.5/weather?q=" + loc + "&APPID=" + APIKEY;
\t sendRequest(url);
}
function k2f(k){
return Math.round(k*(9/5)-459.67);
}
function ascii(a){
\t return String.fromCharCode(a);
}
$('.enter').click(function(event){
event.preventDefault();
var loc = $('#search').val();
var url = "http://api.openweathermap.org/data/2.5/weather?q=" + loc + "&APPID=" + APIKEY;
\t console.log(url);
\t var xmlhttp = new XMLHttpRequest();
\t xmlhttp.onreadystatechange = function(){
\t \t var url = "http://api.openweathermap.org/data/2.5/weather?q=" + loc + "&APPID=" + APIKEY;
\t \t console.log("lol");
\t var data = JSON.parse(xmlhttp.responseText);
\t var datatext = data.id;
\t var name = data.name;
\t \t var locname = name;
\t \t var temptext = k2f(data.main.temp) + ascii(176) + "F";
\t \t console.log(temp);
\t \t console.log(url);
\t \t $('.temperature').text(temptext);
\t $('.city').text(name);
\t };
\t xmlhttp.open("GET", url, true);
\t xmlhttp.send();
});
您可能不想在SO上發佈您的API密鑰。 – Timo
免費的API,但我明白。 – William