Skip to content

Instantly share code, notes, and snippets.

@DzikuVx
Last active December 17, 2015 23:59
Show Gist options
  • Save DzikuVx/5693560 to your computer and use it in GitHub Desktop.
Save DzikuVx/5693560 to your computer and use it in GitHub Desktop.
self.getCurrent = function(onSuccess, onFailure) {
var cache = myStorage.get('current-json');
if (cache === null) {
$.ajax({
url : "http://api.openweathermap.org/data/2.5/weather?id=3083829&mode=json&units=metric",
dataType : 'jsonp',
success : function(json) {
myStorage.set('current-json', json, 1800);
if (onSuccess) {
onSuccess(json);
}
},
error : function() {
if (onFailure) {
onFailure();
} else {
$
.pnotify({
title : 'U la la...',
text : 'Chyba nie udało mi się pobrać wszystkich danych o pogodzie',
type : 'error'
});
}
},
});
} else {
onSuccess(cache);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment