Ich habe ein Projekt, das ich fertig, und wenn Sie es auf Github-Seiten hochladen, funktioniert es nicht. Es werden keine Skripte, extern verknüpfte Schriftarten und API-Daten importiert. Die API unterstützt nur HTTP und Github-Seiten akzeptieren nur HTTPS. Irgendwo herum, ohne APIs zu ändern? Die API ist Openweathermap.Openweathermap API auf Githubpages
$(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();
});
Sie möchten Ihren API-Schlüssel möglicherweise nicht auf SO veröffentlichen. – Timo
Kostenlose API, aber ich verstehe. – William