0
我在這裏爲兩個問題的Zend控制器傳遞一個對象時:
我想通過我在Zend的創建控制器
HTML響應使用end_Json_Encoder ::編碼
public function exampleAction() {
$answers = array();
for($i = 0 ; $i < 3 ; $i++)
{
$answer = new Answer();
$answer->answer_id = 5 ; // for example
$answer->thanked = 'true';// for example
$answers[] = $answer;
}
echo Zend_Json_Encoder::encode($answers);
}
Jquery的JSON對象帖子的功能是:
$.post(
"/memberactions/getthanks/",
{values:values},
function(res){
alert(123);
}
, 'json')
首先問:
爲什麼得到的回答是HTML?響應必須在JSON中?
第二個問題
HTML響應是這樣
[{"__className":"Answer","thanked":"true","answer_id":"5"}]
我怎麼能作出這樣的迴應:
- answer
thanked : true
answer_id : 5
爲JSON對象沒有__className: 「答案」(在答覆中有類名是否會受到傷害)?
$此 - > _ helper-> JSON($答案);與我合作謝謝 – KJA 2012-04-03 10:58:05