Laravel 5.7 - Ajax call and Session :: get ()

0

There are days when I'm banging my head to read data from a Session through a ajax call .

In an application without Framework I do this normally using PHPSESSION , but in Laravel 5.7 I can not do it at all.

My environment: Ubuntu Server + PHP 7.2 + Laravel 5.7 using file as session driver

My ajax call :

$.ajax({
    url: '/nota/consulta?id_cliente='+id_cliente+'&item='+item,
    dataType: 'json',
    success: function(result) {
        console.log(result);
    }
});    

My controller:

public function getNota(Request $request) 
{
    if ($request->session()->has('nota')) 
    {
        $nota = $request->session()->get('nota');
        return response()->json($nota);
    }   
    return response()->json(array('msg'=>'erro'));
}

The session then exists because it starts with View , but the result of ajax does not show the data. I believe I have something in Laravel that is preventing me from reading data from the Session when the request is made by Ajax, because if I open the link in the browser the data appears.

    
asked by anonymous 26.10.2018 / 15:05

1 answer

-1

Pass the data to the route using post, do not pass parameters in ajax url

$.ajax({
    url: '/nota/consulta,
    dataType: 'json',
    method: 'post',
    data: {
      id_cliente: id_cliente,
      item : item
    }
    success: function(result) {
        console.log(result);
    }
});  
    
26.10.2018 / 15:48