我有一个问题,使用JSON, 我有送一个JSON阵列错误发送多个JSON消息
public function repondMessage($etat=true,$message)
{
$msg = array($etat,$message);
return '{"msg":'.json_encode($msg).'}';
}
功能和我正确地得到了JSON数组时只是一个错误发送
这样之一:
if(a=1)
{
echo respondeMessage(false,'Error');
}
和jQuery:
console.log(data);
var resp = jQuery.parseJSON(data);
console.log(resp);
我得到的结果是为我好:
{"msg":[false,"Error"]}
,但是当我得到两个消息在同一时间,当我做出那样的
if(a=1)
{
echo respondeMessage(false,'Error');
}
if(b=1)
{
echo respondeMessage(false,'Error2');
}
测试此发生什么:(我不怎么分开两个Json)
{"msg":[false,"Error"]}{"msg":[false,"Error2"]}
Uncaught SyntaxError: Unexpected token {
无法发送这样的多个响应给他们所有,而不是responces增加和数组并一次发送全部 – Steve 2015-01-15 16:38:22