我用我的小項目的HttpFoundation:use \Symfony\Component\HttpFoundation\JsonResponse as JsonResponse;
新(JSON)響應顯示空白頁(Symfony的HttpFoundation)
不幸的是我所有的反應(試過JsonResponse
,Response
和BinaryFileResponse
)只返回一個空白頁,沒有錯誤並且代碼正常執行,例如
/* Get Inputs */
if (!$data = filter_input(INPUT_GET, 'url', FILTER_VALIDATE_URL)) {
return new JsonResponse(array(
'result' => 'error',
'message' => 'URL is invalid or missing'
));
}else{
return new JsonResponse(array(
'result' => 'success',
'message' => 'FINE'
));
日誌中也沒有錯誤。
任何想法如何解決這個問題?
//更新澄清
$json = new JsonResponse(array(
'result' => 'error',
'message' => 'Encrypt is invalid or missing'
));
echo $json;
回報HTTP/1.0 200 OK Cache-Control: no-cache Content-Type: application/json {"result":"error","message":"Encrypt is invalid or missing"}
但爲何return
不行?
如果你呼應的反應如何?您是否通過Ajax調用服務? – GuyT
不,這是一個直接調用,「回聲」顯示正常 – PrimuS
即使你把'JsonResponse'放在一個變量中嗎? – GuyT