How does ajax.reload() behaves with a 304 return code ?

How does ajax.reload() behaves with a 304 return code ?

azmeukazmeuk Posts: 2Questions: 1Answers: 0
edited April 2016 in Free community support

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

Answers

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin

    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

  • azmeukazmeuk Posts: 2Questions: 1Answers: 0
    edited April 2016

    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 a if (json) guard?

                    if (json) {
                            var error = json.error || json.sError;
                            if ( error ) {
                            _fnLog( oSettings, 0, error );
                            }
                    }
    

    Would you accept such a pull request?
    What about the _fnAjaxUpdateDraw method, should it be triggered at all, as it depends on the json variable?

  • allanallan Posts: 61,893Questions: 1Answers: 10,144 Site admin
    Answer ✓

    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

This discussion has been closed.