var json = xmlhttp.responseText; //ajax response from my php file
obj = JSON.parse(json);
alert(obj.result);
而在我的PHP代碼
$result = 'Hello';
echo '{
"result":"$result",
"count":3
}';
的問題是:當我提醒obj.result
,它顯示"$result"
,而不是顯示Hello
。 我該如何解決這個問題?
我也試過這個。但它顯示了相同的 echo'{0}結果「:''。$ result。'」, 「count」:3 }'; – Nevin
所有** UTF-8 **字符串。 –
Nevin,使用'json_encode' –