Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined index: draw #3

Closed
barentshavet opened this issue Apr 21, 2020 · 3 comments
Closed

Undefined index: draw #3

barentshavet opened this issue Apr 21, 2020 · 3 comments

Comments

@barentshavet
Copy link

I tried to follow the guide and get the following error

Undefined index: draw

Not sure what the problem is?

@monkenWu
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

monkenWu commented Apr 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants