url:“index.php / post / get_post”,此url返回json数据,如...
[{"id":"3","user_id":"2","message":"okiokiokio","is_active":"1","created_at":"2013-05-24 00:00:00","updated_at":"2013-05-24 00:00:00"}]
如何在特定字段中打印数据
$(document).ready(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url();?>index.php/post/get_post",
datatype: 'json',
success: function(data){
$('#divusername').append(data.user_id);
}
});
});
答案 0 :(得分:2)
您需要使用
$('#divusername').append(data[0].user_id);
答案 1 :(得分:1)
这可能会对你有帮助。
$(function() {
$.ajax({ type: "POST", url: "index.php/post/get_post",
datatype: 'json',
success: function(data){
var parsed_data = $.parseJSON(data);
$('#divusername').html(parsed_data.user_id);
}
});
});