How to implement CSRFGuard in ExtJs AjaxRequest?

2019-07-20 05:54发布

问题:

I'm using ExtJs for UI and am doubtful of using CSRFGuard in AjaxRequest of extjs. I'm currently appending the CSRFName and value to the URL of ajax and it is working perfectly fine.

Is there any way that the token name and value could be added as header of Ajax so that it need not be written for each and every AjaxRequest.

Seeking early response. Thanks

回答1:

You could put it in http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Ajax-event-beforerequest

and that would apply to every AJAX request



回答2:

Here is the another solution. It adds to every request the csrf token.

Ext.Ajax.on('beforerequest', function(conn, options) {
    options.params._token = Laravel.csrfToken;
});