Reputation: 71
php json:encode returning undefined on http call on angular controller on server but works well on the 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;
Upvotes: 1
Views: 205
Reputation: 607
For ajax calls, such as this requires the header to be set as application/json, so javascript can easily read it, and also need to make error reporting to false in ajax related API designs
<?php
error_reporting(0);
...
...
...
header('Content-Type:application/json;');
echo $json_response;
this output is easily readable by javascript
Upvotes: 1