2016-12-06 43 views
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(); 
 

 
});

+0

您可能不想在SO上發佈您的API密鑰。 – Timo

+0

免費的API,但我明白。 – William

回答

1

沒有,也不會有這種限制一個簡單的方法,因爲它是爲您的網站的安全性和完整性重要。如果您通過未加密的連接從HTTPS加密頁面訪問資源,用戶將始終看到安全警告。

您可以設置一個通過HTTP訪問API並通過HTTPS將調用傳遞給瀏覽器的代理。請注意,這可能會導致開發工作量相當大的開銷。

最簡單的解決方案可能是切換到另一個天氣數據提供者,considering that HTTPS encryption by default may be a good idea

相關問題