문제

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;
도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top