Php Laravel 5必须在KendoUI网格中发送包含所有请求的令牌
我必须在剑道网格中的每个网格操作(读取除外)中发送_令牌,否则会出现令牌不匹配错误:Php Laravel 5必须在KendoUI网格中发送包含所有请求的令牌,php,laravel,kendo-ui,kendo-grid,laravel-5,Php,Laravel,Kendo Ui,Kendo Grid,Laravel 5,我必须在剑道网格中的每个网格操作(读取除外)中发送_令牌,否则会出现令牌不匹配错误: ... transport: { read: { url: '/core/income-grid/read', dataType: 'json', type: 'get' }, update: { url: '/c
...
transport: {
read: {
url: '/core/income-grid/read',
dataType: 'json',
type: 'get'
},
update: {
url: '/core/income-grid/update',
dataType: 'json',
type: 'post',
data: function(data){
data._token = $('#incomeGrid').data('csrf');
return data;
}
},
create: {
url: '/core/income-grid/create',
dataType: 'json',
type: 'post',
data: function(data){
data._token = $('#incomeGrid').data('csrf');
return data;
}
},
destroy: {
url: '/core/income-grid/destroy',
dataType: 'json',
type: 'post',
data: function(data){
data._token = $('#incomeGrid').data('csrf');
return data;
}
}
},
...
有没有办法解决这个问题,并且仍然拥有csrf令牌提供的保护?在没有令牌传递的情况下,您无法在Laravel中拥有csrf保护 但是,根据,有一个名为transport.parameterMap的方法,它允许对请求参数进行操作。这将允许您在一个位置将令牌作为所有非读取请求的参数,而不必为所有操作单独指定它:
transport: {
...,
parameterMap: function(data, type)
{
if (type !== "read")
data._token = $('#incomeGrid').data('csrf');
return data;
}
}