在退出php时返回json

Mih*_*nca 2 php ajax jquery json return

我一直$.getJSON在使用exit("{'status':true}")(或false)来验证脚本是否正确完成了工作,但是现在我需要脚本来返回值(或数组)。我知道我不能使用 exit('{ "status": $myarray}');。我该怎么用呢?我是php的新手,有可能做类似的return '{ "status": $myarray}';事情吗?提前致谢

Rij*_*ael 5

您可以使用以下功能:

json_encode($data);
Run Code Online (Sandbox Code Playgroud)

请参阅:http//php.net/manual/en/function.json-encode.php