我正試圖在jquery中檢索我的php腳本中生成的以下json。但是,我無法顯示它。如果我提醒它,它只會顯示'未定義'。使用$('#demo').html(data.htmlOutput)來顯示html也不會執行任何操作。請有人指出我做錯了什麼?使用Jquery時無法顯示返回的JSON
$arr = array('htmlOutput' => '<b>hello</b>', 'no_rows' => 'balh');
echo json_encode($arr);
$.post('get-offers.php', $("#offerForm").serialize(), function(data) {
alert (data.htmlOutput);
alert (data.no_rows)
$('#demo').html(data.htmlOutput);
}
我可以看到FB控制檯中的json響應,但它仍然沒有任何作用。
該腳本如何知道將其解析爲JSON? – 2012-02-08 17:13:25
@BarryChapman。它應該知道,請參閱下面的答案。 – gdoron 2012-02-08 17:23:03
@gdoron - 我正在申請'重定向'。我希望他可能會意識到,他沒有告訴腳本,它期望JSON,並可以找到答案:) – 2012-02-08 17:23:59