application\classes\Controller\Ajax.php
Class Controller_AjaxDemo extends Controller_SiteWise_Protected
{
public function action_callme()
{
if ($this->request->is_ajax())
{
// do something
echo json_encode(array('test' => 1,'test2' =>2));
}
else
{
// do something
echo "HI";
}
$this->auto_render = FALSE;
}
}
In you template file e.g. ajax.tpl
<div id="div1"><h2>Will be replaced by Ajax call</h2></div>
<script> $.ajax({ url:"AjaxDemo/callme", success:function(result){ $("#div1").html(result) } }); </script>
No comments:
Post a Comment