Skip to content

Commit

Permalink
Returns the jqXHR for AJAX requests, and returns a jQuery.Defered().p…
Browse files Browse the repository at this point in the history
…romise for cached responses
  • Loading branch information
craigspaeth committed Dec 13, 2011
1 parent 6c00d40 commit 93c9791
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/jquery.offline.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
// store the result in the cache. This function will be
// deferred until later if the user is offline
function getData() {
getJSON(url, data, function(json, status) {
return getJSON(url, data, function(json, status) {
if ( status == 'notmodified' ) {
// Just return if the response has a 304 status code
return false;
Expand Down Expand Up @@ -179,15 +179,20 @@
// If there is anything in the cache, call the callback
// right away, with the "cached" status string
if( text ) {
var response = fn( $.parseJSON(text), "cached", { cachedAt: date } );
if( response === false ) return false;
var obj = $.parseJSON(text);
var response = fn( obj, "cached", { cachedAt: date } );
if( response === false ) {
var dfd = $.Deferred().promise();

This comment has been minimized.

Copy link
@krisselden

krisselden Jan 5, 2012

How does the promise from this Deferred ever get resolved?

dfd.done = function(callback) { callback(obj) };
return dfd;
}
}

// If the user is online, make the Ajax request right away;
// otherwise, make it the most recent callback so it will
// get triggered when the user comes online
if (window.navigator.onLine) {
getData();
return getData();
} else {
mostRecent = getData;
}
Expand All @@ -209,4 +214,4 @@
$.clearJSON = $.noop;
}

})(jQuery);
})(jQuery);

0 comments on commit 93c9791

Please sign in to comment.