How to add Authorization headers to an ajax get request in datatables

How to add Authorization headers to an ajax get request in datatables

rickierickie Posts: 3Questions: 3Answers: 0

Below is a sample code I have, I can't find where to add/plugin in the header.

            processing: true,
            serverSide: true,
            ajax: function (data, callback, settings) {
                let column_order = data.columns[data.order[0].column].data.replace(/\./g, "__");
                $.get(SERVER_URL + "/school/students/list", {
                        limit: data.length,
                        initial: data.start,
                        filters: data.search.value,
                        order_by: column_order,
                    },
                    function (response) {
                        console.log(response.objects)
                        callback({
                            recordsTotal: response.length,
                            recordsFiltered: response.length,
                            data: response.objects,
                        });
                    },
                );
            },

I need your help guys, thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 57,229Questions: 1Answers: 9,111 Site admin
    Answer ✓

    Rather than using $.get use $.ajax. It gives you a lot more control including the a ability to send headers. Check the jQuery docs for details.

    Allan

Sign In or Register to comment.