[eluser]n0xie[/eluser]
Code:
class Ajaxexample extends Controller {
function Ajaxexample()
{
parent::Controller();
}
function myawesomeajaxfunction()
{
// Load model
$this->load->model('somemodel');
// Get some data
$data = $this->somemodel->somemethod();
// return data to the browser either via a view, or since it's an ajax call,
// in the example we just echo it directly from the controller
echo json_encode($data);
}
Call '/ajaxexample/myawesomeajaxfunction' from your view/html.
Mind you there is no validation or sanitation, but you get the idea.