Skip to content

Commit

Permalink
Fixed bug in ajax method with dataType html (#1), disabled default aj…
Browse files Browse the repository at this point in the history
…ax requests caching (#4)
  • Loading branch information
Alexander Krupko committed Jul 14, 2016
1 parent 63476e2 commit 8357d6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions dist/ExtendedJS.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @copyright 2016 Avrora Team www.avrora.team
* @license MIT
* @tutorial http://extendedjs.avrora.team
* @version 1.0.1
* @version 1.0.2
*/

!function()
Expand Down Expand Up @@ -530,7 +530,7 @@
data : {}, // object with request data or FormData
headers : {}, // object with headers
async : true, // if true executes request asynchronously
cache : true, // true for enable caching of request response. Doesn't work jsonp request
cache : false, // true for enable caching of request response. Doesn't work jsonp request
cacheMaxAge : 300, // expires time of response cache in seconds. Default 5 minutes
jsonp : false, // true for jsonp request
uri : '', // request uri
Expand Down Expand Up @@ -756,8 +756,10 @@

if (typeof ajaxCache[P.cache] === 'object' && ajaxCache[P.cache].expires > new Date()) {
status = 'cache';
var response = ajaxCache[P.cache].response;
response instanceof Element && (response = response.cloneNode(true).children);
P.beforeSend.call(xhr);
P.success.call(xhr, ajaxCache[P.cache].response, status);
P.success.call(xhr, response, status);
P.complete.call(xhr, status);
return true;
}
Expand All @@ -783,12 +785,13 @@
var el = document.createElement('div');
el.innerHTML = response;
response = el.children;
var cacheResponse = el.cloneNode(true);
}
}

status === 'success' ? P.success.call(xhr, response, status) : P.error.call(xhr, status);
status === 'success' && P.cache && (ajaxCache[P.cache] = {
response: response,
response: cacheResponse || response,
expires : Date.now() + P.cacheMaxAge * 1e3
});
P.complete.call(xhr, status);
Expand Down
Loading

0 comments on commit 8357d6d

Please sign in to comment.