i have SendRequest object and that class has a function like
request: function(args)
{
return $.ajax.apply(null, args);
};
then a lot of class use SendRequest object to get server response
var prom = SendRequest.request(
{
type: 'GET',
url: _this.uri
});
return $.when(prom).done(function(response)
{
.... do something
});
My goal is in SendRequest.request need to check on window.localStorage first. Whether already has a value or not, if has not any value before then send the request. Otherwise, if already value on localStorage then return $.ajax() object with that saved value before.
request: function(args)
{
var ls = window.localStorage;
var savedResponse = ls.getItem(args.url);
if (savedResponse !=== null)
{
var result = $.ajax();
result.responseText = savedResponse;
result.readyState = 4;
result.status = 'OK';
return result;
}
else
{
return $.ajax.apply(null, args);
}
};
but unfortunately its did not work :( I've been looking but can not find some case like me
I already try this way to how to fool jqXHR to succeed always but its not help much