Add CSRF token send ajax ?

Hello,


When modifying an event it sends a post, but under laravel you have to send a token...


How to add the token to the post?


I tried this but it doesn't work:

var scheduleObj = new ej.schedule.Schedule({
height: '550px',
//locale: 'fr',
timezone: 'UTC',
//selectedDate: new Date(2021, 0, 10),
eventSettings: { dataSource: data2 },
beforeAjaxRequest: "beforeAjaxRequest",
dragStart: function (args) {
args.navigation.enable = true;
}
});
scheduleObj.appendTo('#Schedule');

function beforeAjaxRequest(xhr) {
xhr.setRequestHeader('X-CSRF-TOKEN', $('meta[name="csrf-token"]').attr('content'));
}

1 Reply

RM Ruksar Moosa Sait Syncfusion Team June 2, 2022 10:38 AM UTC

Hi Chris,


We have checked on your requirement and let you know it is not possible to directly set the beforeAjaxRequest. Instead, you need to provide the Key & Value in the headers property of the DataManager like the below code.


new DataManager({ url: SERVICE_URI, adaptor: new ODataAdaptor, headers:[{ 'syncfusion': 'true' }] })

    .executeQuery(new Query())

    .then((e: ReturnOption) => {

        //get result from e.result

    });

 

Kindly refer to the below link and let us know if you need any assistance.

https://ej2.syncfusion.com/javascript/documentation/data/how-to/#adding-custom-headers


Regards,

Ruksar Moosa Sait


Loader.
Up arrow icon