我正在尝试将数据库中的数据添加到jquery中以在网站上呈现.
例如:
使用example.php
function testFunction() {
$data = array()
$mydata = new stdClass;
$mydata->example = 'test';
$data[] = $mydata
return json_encode($data);
}
echo testFunction();
?>
前
的index.html
$.ajax({
type: 'POST',
url: 'example.php',
data: {map: map},
cache: false,
dataType: 'json',
success: function(response) {
console.log(response[0].example);
}
});
输出:
的console.log(响应);
[“test”,$family:function,$constructor:function,each:function,clone:function,clean:function …]
的console.log(响应[0].实施例);
未定义
基本上,我收到的回复很好,当我记录它时它给了我一个有意义的结构.但是我似乎无法找到访问数组内部对象的正确方法,上面的例子只返回undefined.这请问的正确语法是什么?