我陷入了一些json解析,我正在使用jquery的ajax函数填充一些字段,我找到了想要的结果,但不知道如何打印它,以下是我的代码
function logged_in_users() {
$.ajax({
url: site_url+'user/get_loggedin_users',
dataType : 'json',
success: function(result) {
$('#div_id').append(result.email_address)
}
});
}虽然我在控制台响应中得到了如下结果,
[{"email_address":"abc@yahoo.com"},{"email_address":"abc@gmail.com"}]而在我使用的函数端,
echo json_encode($this->login_history_model->get_logged_in_users());任何帮助都将不胜感激。
发布于 2013-05-07 21:40:34
你得到了一组结果,而不只是一个结果,所以你的成功函数将不起作用。
更改为:
success: function(result) {
$.each(result, function(i, v) {
// For each record in the returned array
$('#div_id').append(v.email_address);
});
}https://stackoverflow.com/questions/16420516
复制相似问题