Ajax Bug when connection time out

Ajax Bug when connection time out

lazzylazzy Posts: 21Questions: 8Answers: 0

i got bug .length is not a function when server not return object
line 4732 file jquery.dataTables.js
// Got the data - add it to the table
for ( i=0 ; i<aData.length ; i++ ) {
_fnAddData( settings, aData[i] );
}
we can fix it
if($.isArray((aData)){
for ( i=0 ; i<aData.length ; i++ ) {
_fnAddData( settings, aData[i] );
}
}

Answers

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    Correct - the server needs to return an array for DataTables 1.10. If there is no data, then it should be returning an empty array. I'm afraid I don't consider this to be a bug.

    Having said that, this is something that will change in the next major version of DataTables. The absence of data will also be treated as no data, rather than as an error.

    Allan

  • lazzylazzy Posts: 21Questions: 8Answers: 0

    but if aData = null or undefined aData.length is break it can't continue

  • deliatordeliator Posts: 95Questions: 1Answers: 0
    edited November 2017

    Hello Lazzy,

    I also had that issue with session timeout, i resolve it with that piece of code

    var idleTime = 0;
    
    $(document).ready(function(){
    
        idleTimer = null;
        idleState = false;
        idleWait = 900000;
        
        (function ($) { 
            $(document).ready(function () {
                $('*').bind('mousemove keydown scroll', function () {
                    clearTimeout(idleTimer);
                    if (idleState == true) {
                        // Reactivated event
                        window.location.replace("your login page here");
                    }
                    idleState = false;
                    idleTimer = setTimeout(function () {
                        // Idle Event
                        alert('You have been deconnected');     
                    idleState = true; }, idleWait);
                });
                $("body").trigger("mousemove");
            });
            }) (jQuery)
    })
    

    it's notreally perfect but it works for me :-)

  • allanallan Posts: 63,464Questions: 1Answers: 10,466 Site admin

    but if aData = null or undefined aData.length is break it can't continue

    Correct. That's why I said it needs to be an empty array and not either null or undefined. If there is no data, then DataTables currently expects that to be explicitly the case by there being an empty array.

    Allan

This discussion has been closed.