简体   繁体   中英

How to pass csrf token in laravel 5.4 version for jqgrid?

Trying to pass csrf token from ace admin jqgrid template.

jQuery(grid_selector).jqGrid({          
          data: grid_data,
          datatype: "local",
          height: 250,
          colNames:[' ', 'ID', 'Name', 'Email'],
          colModel:[
            {name:'myac', index:'', width:80, fixed:true, sortable:false, 
             resize:false,
              formatter:'actions', 
              formatoptions:{ 
                keys:true,                
                delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback},
                editformbutton:true, 
                editOptions:{recreateForm: true, beforeShowForm:beforeEditCallback, beforeSubmitCell: beforeSubmitCell}
              }
            },
            {name:'id',index:'id', width:60, sorttype:"int", editable: true},
            {name:'name',index:'name', width:150,editable: true, editoptions:{size:"30",maxlength:"50"}},
            {name:'email',index:'email', width:150,editable: true, editoptions:{size:"30",maxlength:"50"}}
          ], 
          viewrecords : true,
          rowNum:10,
          rowList:[10,20,30],
          pager : pager_selector,
          altRows: true,          
          //toppager: true,
          multiselect: true,
          //multikey: "ctrlKey",
          multiboxonly: true,          
          loadComplete : function() {
            var table = this;
            setTimeout(function(){
              styleCheckbox(table);
              updateActionIcons(table);
              updatePagerIcons(table);
              enableTooltips(table);
            }, 0);
          },      
          editurl: "{{ route('adminCrud', ['menu' => 'users', 'oper' => 'edit']) }}",
          caption: "Users Listings"      
        });

  function beforeSubmitCell(rowid,celname,value,iRow,iCol) {
      alert('rowid => ', rowid);
      return {token:'test'}
    }

Its not entering to beforeSubmitCell, what should be done. How and where exactly csrf token should be passed for all crud operations?

Add the csrf_token to postData and editData options. Something like below.

jQuery(grid_selector).jqGrid({          
      postData: { "_token": {{ csrf_token() }} },
      editData: { "_token": {{ csrf_token() }} },
      ....
      ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM