Question

I am trying to set a cookie in an ajax call, but can't get it to work. I have understood that I need to set it via setCookie on $response->headers. The $cookie variable looks correct, but no cookie is set in the browser.

Code from my controller:

$cookie = Cookie::make('testcookie', array('testvalue' => 'test'), 1000);  
$response = Response::json(array('status' => 'ok'));  
$response->headers->setCookie($cookie);  
return $response;
Était-ce utile?

La solution

I think you are calling this function after the page is initialized. So no cookie headers can be sent after the html tags started.

Refer to this Link

and this will help you

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top