【问题标题】:Laravel 5 having to send token with all requests in KendoUI GridLaravel 5 必须在 Kendo UI Grid 中发送带有所有请求的令牌
【发布时间】:2015-03-14 08:53:49
【问题描述】:

我必须在剑道网格中的每个网格操作(读取除外)中发送 _token,否则我会收到令牌不匹配错误:

...
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 令牌提供的保护?

【问题讨论】:

    标签: php laravel kendo-ui kendo-grid laravel-5


    【解决方案1】:

    在没有传递令牌的情况下,你不能在 Laravel 中获得 CSRF 保护。

    然而,根据Kendo UI Documentation,有一个名为transport.parameterMap 的方法允许对请求参数进行操作。这应该允许您将令牌作为所有非读取请求的参数包含在一个位置,而不必为所有操作单独指定它:

    transport: {
        ...,
        parameterMap: function(data, type)
        {
            if (type !== "read")
                data._token = $('#incomeGrid').data('csrf');
    
            return data;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-16
      • 1970-01-01
      • 2019-06-29
      • 2020-01-25
      • 1970-01-01
      • 2015-06-02
      • 2018-01-25
      • 2012-12-05
      • 2018-01-02
      相关资源
      最近更新 更多