json_encode输出后,为什么会输出undefined

hzhsky1985 2009-12-07 12:51:18
a.php
<?php
$arr = array(
'userinfo_base_name' =>$model['userinfo_base_name'],
'userinfo_base_sex' => $model['userinfo_base_sex'],
'userinfo_base_city' =>$model['userinfo_base_name'],
'userinfo_base_bir' => $model['userinfo_base_sex'],
'userinfo_base_introduction' => $model['userinfo_base_introduction']
);
$json_string = json_encode($arr);
echo $json_string;
?>

<script>
var url="a.php";
dojo.xhrGet({
url: url,
handleAs: "text",
encoding: "utf-8",
load: function(responseText)
{
var json =responseText;
alert(json.userinfo_base_name);
},
error: function(response)
{
alert("失败");
}
});
</script>

responseText输出:{"userinfo_base_name":"\u591c\u795e","userinfo_base_sex":"\u7537","userinfo_base_city":"\u591c\u795e","userinfo_base_bir":"\u7537","userinfo_base_introduction":"good"}

json.userinfo_base_name输出undefined,为什么呢?这句josn文本我验证过没有问题啊
...全文
329 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序猿之殇 2009-12-08
  • 打赏
  • 举报
回复
var json = eval('(' + responseText + ')'); 
程序猿之殇 2009-12-08
  • 打赏
  • 举报
回复
handleAs: "text",
你调用返回的字符串,需要转换为json才可以使用.
var myObject = eval('(' + responseText + ')');


或者直接查看一下dodo如何将接收结果改为json.
江南昆虫 2009-12-08
  • 打赏
  • 举报
回复
eval("var json = "+responseText+";");
hzhsky1985 2009-12-08
  • 打赏
  • 举报
回复
很遗憾,都不可以啊
tony-杨 2009-12-07
  • 打赏
  • 举报
回复
或者在load: function(responseText)中加一句eval("var json = responseText;");
tony-杨 2009-12-07
  • 打赏
  • 举报
回复
handleAs: "text", 修改为json看看

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧