angularjs, $http 304 error, modify data property -
we using ionic framework , angularjs create mobile app phone gap build. have call our api array of items using $http.get, adding etag in header if have data in cache. if data on server has not changed 304 error ok. having trouble modifying data property on response object form server our chached data in local storage.
any appreciated. thanks
return $http({ method: 'get', url: 'http:example.com', params: params, headers: customheader }) .success(function(data, status, headers, config) { // stuff }) .error(function(data, status, headers, config) { if(status == '304') { alert('this data has not changed'); data = chacheddata // change data chached data?? } });
http 304 header code means "not modified", it's not error. according rfc 2616 of http 1.1, server sends headers, not response tells browser use response had in cache.
it should used avoid eavy network traffic.
but in case, if want cache invalidation, not way (but don't think wan't do)
on other hand, angular put 200 in status (even if 304) , shouldn't have bother keeping date data, since retrieve fresher value each time (without bothering if it's cache in server or fresh data server)
Comments
Post a Comment