How to Send AJAX request with CSRF token in CodeIgniter 3

Cross-Site Request Forgery (CSRF) is a way to trick the server that a request sent to it is legitimate while it actually is an unauthorized attempt.

In CodeIgniter, CSRF protection is not enabled by default.

If it is been enabled then CodeIgniter generates a hash for each active user and this is used to verify the request.

Require to send the hash with the AJAX request otherwise, it gives an error – “The action you have requested is not allowed.”.

In this tutorial, I show how you can enable CSRF protection and regenerate hash for the next AJAX request and pass hash in AJAX request in the CodeIgniter project.

How to Send AJAX request with CSRF token in CodeIgniter 3

Read more

DataTables AJAX pagination with Custom filter in CodeIgniter 3

DataTables by default comes with a search filter that can be used to search on all fields or specific fields and display records.

Sometimes, require to add the filter for the particular field only like – adding date range filter, country filter, etc.

DataTables allows for passing data that can read at the server-side script.

In this tutorial, I show how you can add a custom search filter and get records using DataTables in CodeIgniter.

DataTables AJAX pagination with Custom filter in CodeIgniter 3

Read more

DataTables AJAX Pagination with Search and Sort in CodeIgniter 3

CodeIgniter already has a library for pagination.

Which is easier to implement on the page. But you need to customize it to add extra functionality like – search, sorting, rows per page.

Datatables is a jQuery library that comes with all basic functionality which requires pagination.

Need to handle the request and return the response in the specified format.

In this tutorial, I show how you can implement Datatables pagination in CodeIgniter.

DataTables AJAX Pagination with Search and Sort in CodeIgniter 3

Read more