api - Why does Index.html work from my Desktop but not as a GitHub web page? -


when save index.html below desktop , open file, works correctly on browser. when create repository on github , publish webpage latitude , longitude values loaded correctly, while location , temperature values don't load @ all. have idea why happen?

    <!doctype html> <html lang="en"> <head>   <title>geocode  example</title>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>   <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>  </head>   <body> <script> $(document).ready(function() {     var lat, lon, api_url;      $.ajax({           type : 'post',           data: '',           url: "https://www.googleapis.com/geolocation/v1/geolocate?key=aizasycw0lvagdp67ulkwwp7yaibhjoj2ht0apm",        success: function(result){         lat = result['location']['lat'];         $('#lat').html(lat);         lon = result['location']['lng'];                 $('#lng').html(lon);          api_url = 'http://api.openweathermap.org/data/2.5/weather?lat=' +         lat + '&lon=' +         lon + '&units=metric&appid=6b897716ef0e040e1f6c854adfb11822';          $.ajax({           url : api_url,           method : 'get',           success : function (data) {             var temprc = data.main.temp;             var location = data.name;             var desc = data.weather.description;             $('#result').text(location);             var temprf = (temprc * (9/5) + 32);             $('#temp').text(temprf + '° f');           }         });        }     }); }); </script> <span>your latitude : </span><span id="lat"></span><br> <span>your longitude : </span><span id="lng"></span><br> <span>your location:  </span><span id="result"></span><br> <span>the temp: </span><span id="temp"></span><br>  </body> </html> 

i think because of github pages serve https. , if try send http request on https site, request maybe blocked.

so can latitude , longitude through https://www.googleapis.com/geolocation/v1/geolocate, can't data through http://api.openweathermap.org/data/2.5/weather.

this article github may can you.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -