"My question is different" edit: I am on about to export the variable rather than return it in callback function (which is what I am already doing).
I have a function that fetches data from url via jQuery ajax method. On success it calls the callback function that gets the data.
How can I now 'play' with the data?
The bigger picture is to update a chart based on data fetched, based on clicked button.
There will be different cities in URL Api, therefore the function / object will be called multiple times. Also the data I am getting will need manipulating and storing in variable.
What I have for now:
function getMainData(city, apiKey) {
this.city = city;
this.apiKey = apiKey;
var url = "http://api.openweathermap.org/data/2.5/weather?q=";
var ajaxUrl = url + city + apiKey;
var mainData;
$.ajax({
method: "GET",
type: "json",
cache: false,
url: ajaxUrl,
success: myCallback
});
};
function myCallback(data) {
this.data = data;
console.log(data);
};
var showMeData = getMainData("london", "&appid=7ce3e1102e1902e0f878c2a640e95aed");