I want JS to fill my span only if API gave an actual string for both fields. If it didn't then I want it to display default value only in one field. The default value is "Germany".
Here is my code:
$(document).ready(function () {
$.get("https://api.ipdata.co?api-key=[APIKEY]", function (response) {
city = response.city;
country_name = response.country_name;
$("#city").html(city);
$("#country_name").replaceWith(country_name);
}, "jsonp");
});
<span id="city"></span>
<span id="country_name">Germany</span>