I have included the uncompressed version of jquery <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc=" crossorigin="anonymous"></script>
. When I write $.getJSON function globally or in other user define functions and call that function globally it works fine but when I write $.getJSON function inside the addEventListener it give me this error Uncaught TypeError: $.getJSON is not a function
.
city.addEventListener("change", function(){
cityName = this.value;
$.getJSON('https://api.mapbox.com/geocoding/v5/mapbox.places/' + cityName + '.json?access_token=' + API,
function(data) {
json = data;
}
);
lng = json.features[0].geometry.coordinates[0];
lat = json.features[0].geometry.coordinates[1];
zoom = 10;
mapfun();
});
and also when I define $.getJSON in user define the function and call that function in addEventListener it also gives me the same error.
city.addEventListener("change", function(){
cityName = this.value;
getData();
lng = json.features[0].geometry.coordinates[0];
lat = json.features[0].geometry.coordinates[1];
zoom = 10;
mapfun();
});
function getData() {
$.getJSON(url + cityName + '.json?access_token=' + API,
function(data) {
json = data;
}
);
}