Sorry, if this question has been posted before. The ajax function is returning error function and not going to success.
Below is the code snippet.
function getWeather(lat1,lon1){
$.ajax( {
type: “GET”,
dataType: “json”,
url:“http://api.openweathermap.org/data/2.5/weather?lat= ”+lat1 +"&lon="+lon1+"&appid=c5b4e74b23c2533b06b1cd304b46d3b9",
success: function(data){
console.log(“hey”);
},
error: function(){
console.log(lat1+" " + lon1);
}
});
};
Output:
“41.5139193 -81.6747295”
I have tried different things, used getJson, tried in firefox, the url has the JSON object, but the code isn’t going to success function.
Any help is appreciated.
Load ur pen via http instead https
think that because this http://openweathermap.org/price
u can only get ur data via http
1 Like
Hi… thanks for the reply… when i load the pen via http the navigator.geolocation.getcurrentposition shows error. When i load via HTTPS it shows me the coordinates but the success callback in ajax doesn’t work. Can’t seem to know the problem. Two days went by without any progress.
U can make two function as callbacks like
navigator.geolocation.getCurrentPosition(successCallback,errorCallback,
And if ur browser support this geolocation
but can’t determine position then it will call errorCallback
in errorCallback
u can fetch your position getting JSON
from
http://ipinfo.io/json
*i’ll later check what can cause that error http - geolocation u mentioned
Thanks again for the quick reply. That error is the one I have written for the error callback in navigator function. I didn’t think of getting coordinates even in error function. I will try the one you mentioned and will update.
If i get the location from [http://ipinfo.io/json ] in my error callback in navigator function, the ajax is working via HTTP. Thanks a lot for the suggesstion.
1 Like
This guy explain thing
https - for weather api
and
http - for geolocation
opened 01:52AM - 15 Jun 16 UTC
closed 07:35PM - 11 Oct 16 UTC
help wanted
#### Challenge Name
Show the Local Weather
https://www.freecodecamp.com/chal… lenges/show-the-local-weather
#### Issue Description
getCurrentPosition does not work over http. I think that changing the url to codepen.io in that particular challenge would help others campers not thinking their code isn't correct.
#### Browser Information
- Browser Name, Version: Chrome 51.0.2704.84 m
- Operating System: Windows 10
- Mobile, Desktop, or Tablet: Desktop
#### Your Code
``` js
// If relevant, paste all of your challenge code in here
```
#### Screenshot
![image](https://cloud.githubusercontent.com/assets/507366/16065574/6c4c6126-3282-11e6-94cf-4396a1040fcd.png)
Also if u access via https this https://ipinfo.io/json u get msg:
SSL access is restricted to paid plans. See Flexible pricing for the most accurate IP data - IPinfo.io for more details, or contact us via Contact Sales - IPinfo.io
1 Like