【发布时间】:2012-02-08 17:11:39
【问题描述】:
我正在尝试使用 jquery 检索在我的 php 脚本中生成的以下 json。但是,我无法显示它。如果我提醒它,它只会显示“未定义”。使用 $('#demo').html(data.htmlOutput) 来显示 html 也无济于事。请有人指出我做错了什么?
$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?
-
@BarryChapman。应该知道的,看我下面的回答。
-
@gdoron - 我正在应用“重定向”。我希望他可能意识到他并没有告诉脚本它需要 json 并且可以找到答案:)
-
@BarryChapman。 jQuery 团队在他们的文档中说他们默认使用 Intelligent Guess...所以它本来可以工作...