$('.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值:輸出一串json返回值
{"idwallPosts":"803"}{"idwallPosts":"798"}{"idwallPosts":"797"}{"idwallPosts":"796"}{"idwallPosts":"793"}{"idwallPosts":"792"}{"idwallPosts":"789"}{"idwallPosts":"785"}{"idwallPosts":"780"}
下面是我笨代碼:
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));
}
}
你的JSON值應列爲包裹在一個單一的屬性對象..'{「key1」:「val」,「key2」:「val2」,...} – Stphane