0
Some days I’m banging my head to read a dice Session
through a ajax
call
.
In an application without Framework
I do this normally using the PHPSESSION
, however in Laravel 5.7
I can’t do it at all.
My environment: Ubuntu + PHP 7.2 + Laravel 5.7 server using file as Session driver
Man 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 exists because I print it on View
, but the result of ajax
does not carry the data. I believe that there is something in the Laravel
which is preventing me from reading Session data when the request is made by Ajax, because if I open the link in the browser the data appears.
What is your route?
– novic
Hi Virgilio, I am using Routes web.php with the following route: Route::get('/note/query', 'Trocacontroller@getnote');
– Fábio Hargreaves Vieira
console.log returns what?
– novic