Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions 2-31/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,27 @@
caches.match(url).then(function(response) {
if (response) {
response.json().then(function(json) {
json.key = key;
json.label = label;
app.updateForecastCard(json);
// Only update if th XHR is still pending, otherwise the XHR
// has already returned and provided the latest data
if( app.hasRequestPending ) {
json.key = key;
json.label = label;
app.updateForecastCard(json);
}
});
}
});
}
// Make the XHR to get the data, then update the card
app.hasRequestPending = true;
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState === XMLHttpRequest.DONE) {
if (request.status === 200) {
var response = JSON.parse(request.response);
response.key = key;
response.label = label;
app.hasRequestPending = false;
app.updateForecastCard(response);
}
}
Expand Down