在php中返回值不是字符串

时间:2016-05-26 15:04:29

标签: php angularjs laravel-5.1 return-value

我在php中有一个回复函数的邮件功能。

浏览器的开发人员工具将响应显示为字符串,但是当我在前端捕获该响应时,使用回调函数,它显示为JSON对象。

所以在屏幕上打印的是:

{"0":"A","1":" ","2":"t","3":"e","4":"m","5":"p","6":"o","7":"r","8":"a","9":"r","10":"y","11":" ","12":"p","13":"a","14":"s","15":"s","16":"w","17":"o","18":"r","19":"d","20":" ","21":"h","22":"a","23":"s","24":" ","25":"b","26":"e","27":"e","28":"n","29":" ","30":"s","31":"e","32":"n","33":"t","34":" ","35":"t","36":"o","37":" ","38":"y","39":"o","40":"u","41":"r","42":" ","43":"e","44":"m","45":"a","46":"i","47":"l"}

我不明白为什么?我正在使用Laravel 5.1和AngularJS作为前端。

以下是该函数的代码:

 if (Mail::send('test-view', ['pass' => $pass], function($message) use ($data)
    {
    $message->to('esolorzano@renovatiocloud.com', 'Tarzan de la Selva')->subject('Password Reset');
    })){
       echo "A temporary password has been sent to your email"; 
    }else {
        echo "There was an error sending the temporary password";
    }

我刚修好了,我做了这个

 $response = new \stdClass();
        $response->message = "A temporary password was sent to your email";
       return json_encode($response); 

然后在角度我只是使用response.message,就是这样。感谢

1 个答案:

答案 0 :(得分:0)

我修好了

 $response = new \stdClass();
        $response->message = "A temporary password was sent to your email";
       return json_encode($response); 

然后在Angular中,我只使用response.message。