2016-11-04 72 views
2

我在symfony應用程序的工作,我試圖刪除記得我的cookie,使用下面的代碼:的Symfony:發送jsonResponse

$response->headers->clearCookie($cookieName,'/');

我呼籲這個response->send()方法生效,這完美的作品用一個簡單的迴應,但是當我嘗試用jsonResponse,功能使用send()返回此錯誤:

JSON.parse: unexpected non-whitespace character after JSON data

有什麼錯我的JSON數據,即使我沒有指定數據似乎發送功能只是不與jsonResponse

工作這裏是我的jsonResponse代碼:

$array = array('message'=>'your account is disabled','success'=>false); 
$response = new JsonResponse($array); 
$response->send(); //this triggers the error 

您的幫助將不勝感激!

+0

它可能不會改變任何東西,但你應該返回'$ response'行動,而不是調用'直接發送()'方法。 –

+0

你確定這是一個PHP相關的錯誤?我在Javascript方面看到了這個錯誤。 – felipsmartins

+0

Jakub如果我返回響應它不會清除cookie,所以我必須使用send方法產生這個錯誤,並添加返回響應wony改變一個東西, – ZeSoft

回答

1

您可以使用此代碼在控制器

$array = array('message'=>'your account is disabled','success'=>false); 
return new JsonResponse($array); 

Send, in controller is not valid and you can use return in controller.

+0

如果我使用不帶函數的返回發送deleteCookie不起作用 – ZeSoft

+0

實際上它在控制器中工作,但不在驗證處理程序中,特別是在使用remember_me cookie時 – ZeSoft