|
$.ajax({
type:"post",
data: "picID=" + $(this).attr("id"),
url:"<?=site_url('photogallery/getPhoto')?>",
success: function(result) {
alert(
result
); },
error: function() {alert("ajax error");}
});
Controller层:
function getPhoto()
{
//query the picture from model
$query = $this->photomodel->getPic($this->input->xss_clean($this->input->post('picID')));
if($query->num_rows() > 0)
{
$row = $query->row();
$output = "<divclass='winBar'><ul><li>_</li><li>x</li></ul></div><divclass='winContent'><div id='photo_title'>" . $row->photoName . "</div><div id='photo_item'>" . $row->photoLink . "</div><div id='photo_comment'>" . $row->comment . "</div></div>";
}
else
$output = "no picture was found";
echo($output);
}
我想问的是,如何实现在 Controller层 不写“echo” 而是是 “return” ?
因为我换成“return” 的时候, Ajax不能获取返回值 ! 但是又想不到能在view视图里面输出的方法......................
|
|