Laravel有时我会丢失会话中存储的数据

时间:2017-11-02 13:54:50

标签: php laravel session

我使用ajax将变量传递给控制器​​,控制器在会话中存储变量但有时显示为空,即使我在输入字段中插入数据

 $(document).on('click', '.btn_getbids', function(e) {
  $.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
    }});
   e.preventDefault();
 var form = document.forms.namedItem("booking-form"); 
 var formData = new FormData(form); 
 $.ajax({
    type: 'POST',
    url: 'addItem',
    contentType: false, 
    data: formData,
    processData: false,
    success: function (data) {   },
    });});

控制器

public function addItem(Request $request) {


$request->session()->flash('country', $request->country);
$request->session()->flash('administrative_area_level_1', $request->administrative_area_level_1);
$request->session()->flash('locality', $request->locality);
    }

Diaplaay Blade

      <div class="alert alert-success">
                     {{Session::get('country')}} <br>
                      {{Session::get('administrative_area_level_1')}} <br>
                     {{Session::get('locality')}} 

      </div>

0 个答案:

没有答案