【发布时间】:2016-05-26 15:04:28
【问题描述】:
我在 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 就是这样。谢谢
【问题讨论】:
-
我们需要更多相关的代码来帮助解决这个问题。
-
R u 在从 PHP 返回值时使用任何编码/解码函数?
-
不,我编辑了问题,以便您可以看到 php 函数
-
如果您注意到,json 字符串包含一个对象,该对象以字符串
A temporary password has been sent to your email的每个字符作为属性。您可能启用了某种输出缓冲,然后将其转换为此。
标签: php angularjs laravel-5.1 return-value