php-json:encode在服务器上的angular控制器上的http调用中返回undefined,但在localh


php json:encode returning undefined on http call on angular controller on server but works well on the localhost

php-json:encode在服务器上的angular控制器上的http调用上返回undefined,但在localhost上运行良好。

if( hash_equals($hashed_password, crypt($password, $hashed_password))){
    $pass = "true";
    $result = array('pass' => $pass, 'FirstName' => $f_name,
    'LastName'  => $l_name,'id' => $id);
}else{
    $pass = False;
    $result = array('pass' => $pass, 'FirstName' => "", 'LastName' => ""
 , 'id' => $id);    
}
$json_response = json_encode($result);
echo $json_response;

对于ajax调用,这样需要将头设置为application/json,这样javascript就可以轻松读取它,并且还需要在与ajax相关的API设计中将错误报告为false

<?php
error_reporting(0);
...
...
...
header('Content-Type:application/json;');
echo $json_response;

这个输出很容易被javascript 读取