我有一個問題,使用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