How to get json file from local weather app of free code camp?

I don’t know how to get a json file from local weather api of free code camp.

Do I have to learn Ajax or is there any other way.
I have used $.getJSON() in previous project s.

Its actually found in the JSON and AJAX challanges :slight_smile:

Here’s my base code (still has some errors, I’m working on it too!)

// ====NAMES FOR LATTITUDE AND LONGITUDE
  var userLat;
  var userLon;

  // ====SET LAT AND LON TO CURRENT GEOPOSITION COORDINATES

  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(position) {
      userLat = position.coords.latitude;
      userLon =  position.coords.longitude;
    });
  } else {
    // PROMPT NO SUPPORT
  }

  // =========AJAX REQUEST
  var api = 'https://fcc-weather-api.glitch.me/api/current?lat='  userLat  '&lon='  userLon;
  $.getJSON(api, function(json){
    console.log(json);
    $("#data").html(json);
  });

I found one error in your code that you didn’t used ‘+’ concatination in your api variable.

var api = ‘https://fcc-weather-api.glitch.me/api/current?lat=’ + userLat + ‘&lon=’ + userLon;

// this is my code and it works.

$(document).ready(function(){
var userLat = ‘lat=’;
var userLon = ‘lon=’;

// seting latitude and longitude to current position
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
userLat += position.coords.latitude;
userLon += position.coords.longitude;
});
} else{
// No support for navigation
}

$(document).ready(function(){
var userLat = ‘lat=’;
var userLon = ‘lon=’;

// seting latitude and longitude to current position
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position){
userLat += position.coords.latitude;
userLon += position.coords.longitude;
});
} else{
// No support for navigation
}

var api = 'https://fcc-weather-api.glitch.me/api/current?’ + userLat + ‘&’ + userLon;

$.getJSON(api, function(json){
console.log(json);
});
});