php - Two ajax calls , Session gets the first one but not the second , laravel 5.4 -


i'm having 2 ajax posts called @ different times , posting 2 different urls , first 1 works when print echo session('first');

but second 1 prints empty . did var_dump('session::all'); , realized session not second variable posted . what's weird 2 ajax complete print variables on console upon completion of post. can issue here ? code below :

blade

first select

 <!---language section -->         <select class="user-profile clearfix" name="locale" id="languageswitcher">                     <option>{{trans('app.language')}}</option>                     <option value="en">english</option>                     <option value="zh">中文</option>                     </select>      <!--language section end --> 

seconde blade

<div class="form-group">                   {!!form::label('group',trans('app.select_group'))!!}                   {!! form::select('group',$groups, null,['class'=>'form-control','id'=>'group']) !!}    </div> 

routes

first route

route::post('/language-chooser','languagecontroller@changelanguage');  route::post('/language/',array(    'before'=>'csrf',    'as'=>'language-chooser',    'uses'=>'languagecontroller@changelanguage', )); 

second route

 route::post('/groupchooser','setgroupcontroller@index');   route::post('/setgroup',array(     'before'=>'csrf',     'as'=>'groupchooser',     'uses'=>'setgroupcontroller@index',  )); 

middlewares

first middleware

public function handle($request, closure $next) {      if(session::has('locale')){            $locale=session('locale');     }     else{         $locale='en';      }     if(session('group'))     {         return view('home');     }     app::setlocale($locale);     return $next($request); } 

second middleware

public function handle($request, closure $next) {      if(session::has('group'))     {         echo session('group');     }       return $next($request); } 

script

$(document).ready(function(){   $("#languageswitcher").change(function(){      var locale=$(this).val();    //alert(111);    //console.log(111);   var _token =$("input[name=_token]").val();      $.ajax({        url:"/language",        type:"post",        data:{locale:locale,_token:_token},        datatype:'json',        success:function(data){           console.log(data);          },        error: function(ts) {              //alert(ts.responsetext);        },        beforesend:function(){            console.log(locale);         },        complete:function(data){             window.location.reload(true);         }    });   }) ;    $("#group").change(function(){     sessionstorage.clear();    var group=$(this).val();    //alert(111);    //console.log(111);   var _token =$("input[name=_token]").val();      $.ajax({        url:"/setgroup",        type:"post",        data:{group:group,_token:_token},        datatype:'json',        success:function(data){          },        error: function(ts) {              //alert(ts.responsetext);       },        beforesend:function(){            console.log(group);         },        complete:function(){            window.location.reload(true);         }      });      }) ;    }); 


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -