You don't need a hidden field. You can "inject" a php variable into Javascript code.
Example:
In the controller, load the view and put it in a variable:
The 3rd argument of $this->load->view() will return the value.
The echo in the controller function will return the result to the Ajax call.
Maybe loading the view as usual will work as well, but I didn't test that.
Example:
Code:
$('#some_button').click(function(){
var url = "<?= site_url('groups/anotherfunction/' . $page_id);?>";
$.post( url )
.done(function(data) {
$('#some_element').html(data);
});
});
In the controller, load the view and put it in a variable:
PHP Code:
$dynamic_html = $this->load->view('group/anotherFunction',NULL,TRUE);
echo $dynamic_html;
The echo in the controller function will return the result to the Ajax call.
Maybe loading the view as usual will work as well, but I didn't test that.