Adding A HTTP Header to the Ajax request.

Adding A HTTP Header to the Ajax request.

matt1982matt1982 Posts: 1Questions: 1Answers: 0

Hey I am struggling to try and add a HTTP header to the request when I have an ajax datatable.

I am trying to add a header called Apitoken to my request. In jquery I have been doing:

headers: { 'Apitoken': apiToken },

My table is defined as follows:

var table = $('#dataTables-site-vehicle').DataTable( {
            "processing": false,
            "serverSide": false,
            "ajax":{
                url: baseApiUrl +"site/" + siteId + '/vehicles',
                type: "GET",
            });

However I am struggling to find any reference to changing the request made. I am using datatables 1.10 and was unable to find anything. Anyone know how to do this or at least know where I can find the docs to assist.

Many thanks for your time. Im sure I am just missing some school boy errors.

Matthew

Answers

  • allanallan Posts: 62,933Questions: 1Answers: 10,353 Site admin
    var table = $('#dataTables-site-vehicle').DataTable( {
                "processing": false,
                "serverSide": false,
                "ajax":{
                    url: baseApiUrl +"site/" + siteId + '/vehicles',
                    type: "GET",
                    headers: { 'Apitoken': apiToken },
                });
    

    should do it. The ajax option is just basically pass through to jQuery's $.ajax.

    Allan

This discussion has been closed.