getWeatherData: function(name) {
var adress = 'http://api.openweathermap.org/data/2.5/weather/?q=' + name + '&appid=0b36702db9b2b0d39a1209d306befff5';
/* native JS */
request = new XMLHttpRequest();
request.open('GET', adress);
request.onreadystatechange = function() {
if ((request.readyState === 4) && (request.status === 200)) {
var info = JSON.parse(request.responseText),
temp = info.main.temp - 273.15,
country = info.sys.country,
descr = info.weather[0].description,
data = [name, country, temp, descr];
console.log(data); // [Array]
return data;
}
};
request.send();
},
getWeatherData: function(name, callback) {
var adress = 'http://api.openweathermap.org/data/2.5/weather/?q=' + name + '&appid=0b36702db9b2b0d39a1209d306befff5';
/* native JS */
request = new XMLHttpRequest();
request.open('GET', adress);
request.onreadystatechange = function() {
if ((request.readyState === 4) && (request.status === 200)) {
var info = JSON.parse(request.responseText),
temp = info.main.temp - 273.15,
country = info.sys.country,
descr = info.weather[0].description,
data = [name, country, temp, descr];
console.log(data); // [Array]
callback(data);
}
};
request.send();
}
obj.getWeatherData('someName',function(data){
//код дальше
})