$('.more').live("click",function() {
var id = $('.wallPosts:last').attr("relOne");
$.ajax({
type: "POST",
url: "<?=base_url()?>index.php/regUserDash/ajaxMore",
data: {id: id},
cache: false,
success: function(data) {
$("#morebox").append(data.idWallPosts);
}
});
});
使用上面的代码,我将如何输出一堆 json 返回值?以下是我的 json 值:
{"idwallPosts":"803"}{"idwallPosts":"798"}{"idwallPosts":"797"}{"idwallPosts":"796"}{"idwallPosts":"793"}{"idwallPosts":"792"}{"idwallPosts":"789"}{"idwallPosts":"785"}{"idwallPosts":"780"}
下面是我的codeigniter代码:
public function ajaxMore() {
$id = $this->input->post('id');
$result = $this->db->query("SELECT * FROM wallposts WHERE idwallPosts < '$id' ORDER BY idwallPosts DESC LIMIT 9");
foreach($result->result() as $row) {
echo json_encode(array('idwallPosts' => $row->idwallPosts));
}
}