我正在尝试从php中获取json对象,以便在ajax中使用。以下是我的ajax代码:
$.ajax({
type: 'get',
url: eventsListPath,
dataType : "json",
data: {},
success: function (data) {
$('#eventInformation').html(data.table);
alert(data.table);
}
});
我的PHP代码:
$obj->table="hey";
echo json_encode($obj, JSON_UNESCAPED_SLASHES);
但是这条线
alert(data.table);
返回'undefined',有什么想法吗?
success
中尝试使用console.log(data)
。告诉我结果。 - iplus26