【发布时间】:2016-04-05 06:37:12
【问题描述】:
我已向我的服务器请求用户提交的帖子列表。但作为响应,我得到一个包含 stdClass 对象数组的字符串。如果它是实际数组,那不会是问题。但它是一个刺痛。像下面这样:
" array(
[0]=>stdClass('title'='title of post','post_id'=4),
[1]=>stdClass('title'='title of post','post_id'=4)
)"
typeof(response) 给了我“字符串”。我的问题是,我如何才能从中访问单个元素?
代码:
$.ajax('../includes/ajaxpostinfo.php',{
data:data,
type:"POST",
success:function(response){
alert(typeof(response)); // it prints out "string"
},
error:function(response){
alert(response);
}
});
【问题讨论】:
-
复制您的
ajaxpostinfo.php代码。 -
您需要使用 PHP API 中的
return json_encode(responseArray);。不是var_dump它。
标签: javascript php jquery arrays ajax