How to avoid RangeError maximum call stack size exceeded?

How to avoid RangeError maximum call stack size exceeded?

murciego.martinmurciego.martin Posts: 7Questions: 0Answers: 0

Enclosing certain statements that load or initialize the DataTable. I have for example a setTimeOut that refreshes it every 30 seconds with ajax.reload.

But it is a component that has to launch this error and it would be good to publish how to avoid these errors and get the best performance. Because it uses many resources to achieve desired functionalities

Replies

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    That error is specific to your setup. Using setTimeout with ajax.reload() in this example works without error:
    http://live.datatables.net/gekepesa/1/edit

    RangeError maximum call stack size exceeded

    Sounds like you have a continuous loop somewhere. Without seeing your code its hard to say what the problem is. Can you post a link to your page or update the example to replicate your issue?

    Just to make sure you have the value for your setTimeout function as 30000 correct?

    Kevin

  • murciego.martinmurciego.martin Posts: 7Questions: 0Answers: 0
    edited November 2018

    Actually what I meant to say setTimeInterval()
    Maybe I need to control with a flag when refreshing the dataTables every so often in case there is an operation being performed that does not call ajax.reload at that moment.

        setInterval( function () {
            try{
                myDatatable.ajax.reload(function(){
                    console.log('\n[' + moment(new Date()).format("DD-MM-YYYY HH:mm:ss") + ']: Se ha actualizado el contenido del DataTables...');
                }, false);
            } catch(e){
                console.log('Error al refrescar automaticamente la tabla de accesorios: ', e);
            }
        }, 30000 );
    
  • murciego.martinmurciego.martin Posts: 7Questions: 0Answers: 0

    I found in stackoverflow that a function without parenthesis must be passed to avoid recursion within the call to setInterval (). It is something that I run to periodically refresh the dataTables but if there were any pending operation or CRUD type it would be necessary to use a state or flag variable,

        //Refresh / Reload DataTables cada 30 segundos
        try{
            //Se llama sin parentesis para evitar recursion sobre function refrescarDataTable() 
            setInterval( refrescarDataTable, 30000 ); 
        }catch(e){
            console.log('Error al refrescar dataTable: ', e);
        }
    
        function refrescarDataTable() {
            myDatatable.ajax.reload(function(){
                console.log('\n[' + moment(new Date()).format("DD-MM-YYYY HH:mm:ss") + ']: Se ha actualizado el contenido del DataTables...');
            }, false);
        }
    
This discussion has been closed.