Override ajax global option when using language url

Override ajax global option when using language url

CaptainNemoCaptainNemo Posts: 13Questions: 6Answers: 1

Hello,

Using Laravel Mix, i defined global options for ajax calls.

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    },
    timeout : 5000  
});

All my Datatables have the same configuration, like this :

$('.datatable').DataTable({
    "order": [],
    "language": {
        "url": "//cdn.datatables.net/plug-ins/1.10.21/i18n/French.json"
    }
});

Unfortunately, calling a remote i18n (as defined in my DT config) with a custom header (as defined in my global ajax setup above) triggers an error

Have you got an option to override the headers ajax locally in the DT ?

Thanks !

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,453Questions: 1Answers: 10,055 Site admin
    Answer ✓

    No - this is the code.

    If you click the "Network" tab in the browser's inspector and view the headers, is your custom header there?

    Also, is your $.ajaxSetup definitely happening before the DataTable is initialised?

    Thanks,
    Allan

  • CaptainNemoCaptainNemo Posts: 13Questions: 6Answers: 1

    Well you're right... I change it, and i set my global Ajax config after datatables init and it's ok...
    Thanks !

This discussion has been closed.