monkenWu / TablesIgniter

Tableslgniter is an addins base on CodeIgniter4. It will help you use jQuery Datatables in server side mode.
https://tablesigniter.monken.tw/
MIT License
14 stars 7 forks source link

Undefined index: draw #3

Closed barentshavet closed 4 years ago

barentshavet commented 4 years ago

I tried to follow the guide and get the following error

Undefined index: draw

Not sure what the problem is?

monkenWu commented 4 years ago

Hi, in the official datatables doc ,it is mentioned that the function of the "draw" index is to draw the counter. Please try to find out if the draw index exists in the ajax request. like this:

barentshavet commented 4 years ago

Thanks for the quick reply. Actually, I found out the issue was CSRF.

Do you have any examples of how to send the CSRF tokens with the Ajax request?

monkenWu commented 4 years ago

Okay,I see. You can read CI4 User Guide - Security Class,It is the built-in security library of Codeigniter4. . You can use "csrf token ()" and "csrf hash ()" to create the CSRF certification field attached to the ajax post. Your datatables initialization code may look like this

$('#fullTable').DataTable({
    "aoColumnDefs": [{ 
        "bSortable": false,
        "aTargets": [ 0,1 ] 
    }],
    "order":[],
    "serverSide":true,
    "ajax":{
        url:"<?=base_url('home/fullTable')?>",
        type:'POST',
        data : {
            <?=csrf_token()?> : "<?=csrf_hash()?>"
        }
    }
});

In the user guide,other configurations will be explained in detail, thank you.