Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Returns the jqXHR for AJAX requests, and returns a jQuery.Defered().p…

…romise for cached responses
  • Loading branch information...
commit 93c9791569890c3c46740b56d3a322eee95df4d7 1 parent 6c00d40
Craig Spaeth authored
Showing with 10 additions and 5 deletions.
  1. +10 −5 lib/jquery.offline.js
View
15 lib/jquery.offline.js
@@ -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;
@@ -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();

How does the promise from this Deferred ever get resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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;
}
@@ -209,4 +214,4 @@
$.clearJSON = $.noop;
}
-})(jQuery);
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.