[eluser]Krzemo[/eluser]
Some code below from top of my head (no warranty though
)
Code:
//in da controller
function blog()
{
$id = $this->input->post('id');
if($this->_is_ajax())
{
$json = null;
$json->results = $this->model_blog->get_blog($id);
$this->output->set_header('Content-type: application/x-json');
$d['message'] = json_encode($json);
$this->load->view('admin/vjson_response_wrapper', $d); //this simple view just doing <?=$message?>
}
else
{
//here you put regular code for loading view if its not ajax (usefull when browser JS is off or it google indexing)
}
}
//after Jamie
function _is_ajax() {
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') ? TRUE : FALSE;
}
and the rest is done by javascript (me like jQuery)
Code:
//this is to be used with an event
$.post('/admin/blog', {'id': $('input#id').val()},
function(data){
$('input#username').val(data.username);
$('input#first_name').val(data.first_name);
}
, 'json');