Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
  • Jun 19 2020 20:09
    @krisb1220 banned @Gastony
  • May 14 2020 22:39
    @bjorno43 banned @minitechtips_twitter
  • May 14 2020 22:38
    @bjorno43 banned @real-action
  • Feb 01 2020 00:27
    @bjorno43 banned @Ndoua
  • Jan 07 2020 03:10
    @bjorno43 banned @doctor-sam
  • Aug 17 2019 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 2019 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 2019 17:13
    @mstellaluna banned @cmal
  • Jan 08 2019 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
Will Kempster
@ayyazzafar thanks for replying. I am doing the task on codepen and not locally hosting, is that okay?
williamface sends brownie points to @ayyazzafar :sparkles: :thumbsup: :sparkles:
:cookie: 8 | @ayyazzafar |http://www.freecodecamp.com/ayyazzafar

sorry this one is more organized

var lat, lon, weather;
if ('geolocation' in navigator) {
  navigator.geolocation.getCurrentPosition(location, error);
} else {
  alert("Geolocation not supported");

function error() {
  alert("Sorry you are in outer space");

function location(position) {
  lat = position.coords.latitude;
  lon = position.coords.longitude;

  weather = "api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + lon + "&units=metric&APPID=";

    url: weather,
    dataType: 'jsonp',
    success: function(data) {
      var temp = data.main.temp;


I didnt want to share my api

@WilliamFace can you paste you codepen link?
you likely need to add &callback=? to the end of your url
Ayyaz Zafar
@WilliamFace there are possibilities that codepen has some restrictions. But please share your codepen. May be we can find some solution for you.
Will Kempster
@dhcodes of course, here we go: http://codepen.io/dilliam/pen/rLbxZV
I have been messing around with this for about an hour now and changed a lot so there may be some stupid errors that I am not picking up :/
well i think it may be the s in https
but even if i remove it, it calls the https page
so idk, still messing with it
Will Kempster
I had that issue with the weather App and ended up using this URL proxy service - https://crossorigin.me/
But no matter what I do I can't make this one work. I even tried copying in code from tutorials (forgive me) just too see if I as going mad but it was still throwing the same error
@WilliamFace i just used that prepend and it did work
add an s to your codepen url
https:// your codepen link
prepend your url with https://crossorigin.me
change your success function to console.log(request)
and you will see an XML return in the console
@WilliamFace fwiw, I find that jquery.getJSON is an easier approach for apis or AJAX even may be easier than XML
but that could be because I don't know how to parse XML
if you want, I can fork your project
and send a link
Will Kempster
If you could, I'd be really grateful
Just added the s to http and appended with https://crossorigin.me and the error has gone but the API is still not being called and not adding the response text to searchObj
@dhcodes maybe I am just trying to be too clever no using get.JSON! I did the weather app with it and then re-wrote it for practice with vanilla js, thought I could go ahead and do this one in vanilla but obviosuly not :smile:
*not using get.JSON
here you go
Will Kempster
@dhcodes thanks!! Finally it's called the API :smile: for someone reason though it wont parse the responseText to JSON when using JSON.prase(request.responseText)
williamface sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1347 | @dhcodes |http://www.freecodecamp.com/dhcodes
Will Kempster
Which is really weird as the information is clearly there in responseText
@WilliamFace i think it's because your response is coming back as xml and not json
Will Kempster
@dhcodes ahhhhhhh that makes sense ! The error it is throwing up now is 'unexpected / at position blah blah' which must be the / at the start of the XML
yeah, i'm not sure there's a good way to convert it from xml though
idk why it isn't giving json since you request that in the format
Will Kempster
yeah it's really weird, I actually think it is returning JSON but /**/( is appended to the start of the file so you can't use JSON.parse
never seen that before
Just tried it on my weather app and the /**/( is not there
Stephen James
@WilliamFace Can you save your codepen page, I'd like to take a look at the latest.
@WilliamFace yeah but if you console.log(request.responseText) it is definitely xml
Will Kempster
@sjames1958gm here you go https://codepen.io/dilliam/pen/rLbxZV
can someone help me?
we can try
what's up
i can't figure out how to change the colors of my navbar. any help is greatly appreciated
@leena-d you have set the background-color to black
Stephen James
@WilliamFace Since you are using that proxy URL - remove callback=? and change format back to json.