How to fix browser cache and notmodified
respond for JSON? jQuery.ajax({ifModified:true,cache:true})
JSON request break on data
respond.
First time browser request http://localhost/api returns status 200 OK
and nexts 304 Not Modified
$.ajax({
type:"GET",
url:'http://localhost/api', // {"content"="Hello!"}
dataType:'json',
cache:true,
ifModified:true, // Lets respond `304:notmodified`
success:function(data,textStatus,jqXHR){
console.debug(jqXHR.status+':'+textStatus);
console.debug(data); // Why on repeated request returns `undefined`?
}
});
XHR first time returns ok:
200:success
Object {content="Hello!"}
but on next times returns data
undefined:
304:notmodified
undefined
How to solve it? It seems jQuery 1.5.1 bug. Expected result:
304:notmodified
Object {content="Hello!"}
Try adding a random number to the end of your url as a param.