How does ajax.reload() behaves with a 304 return code ?
How does ajax.reload() behaves with a 304 return code ?
azmeuk
Posts: 2Questions: 1Answers: 0
Hi. I use datatables 1.10.11. My website sometimes returns a "304 NOT MODIFIED" http response. If the ajax.reload() function stumble upon a 304 return code, it raises an exception TypeError: json is undefined
from jquery.dataTables.js:2552. Did I miss some configuration? Is it a bug?
PS: serverSide
option is enabled.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This is a jQuery ticket on the topic.
DataTables just uses
$.ajax
for the Ajax fetch of data. I'm not sure I fully agree with the resolution of the bug, although I am a little surprised that the browser doesn't give the cached data.That all sounds a bit messy!
Allan
I forgot to say that
serverSide
option is enabled.The behavior described by this bug report tells us that the
json
var is not defined with 304 error codes. Maybe there is actually a little bug in datatables. What about surrounding this piece of code with aif (json)
guard?Would you accept such a pull request?
What about the
_fnAjaxUpdateDraw
method, should it be triggered at all, as it depends on thejson
variable?The problem with that is that it will leave DataTables in an undefined state. It assumes that valid JSON will be returned - anything else is in error.
The pull request I would accept is for it to detect the 304 not changed and therefore just use the same JSON as before (i.e. it still goes through the new draw).
Allan