Imagine I have the following ‘partial’ which is generated through a bunch of views:
<div id="funstuff">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
</div>
Through the usage of codeigniter, I can reuse views (which I do a lot), and I would like to dynamically replace the ‘funstuff’ div with the contents from another view. Its controller method is still in the same class:
class FunnyThings extends CI_Controller {
public function index() {
$this->load->view('funpage_view');
}
public function funview() {
$this->load->view('fun_partial_view');
}
}
Basically, with Jquery I can replace that view with different content:
$('#funstuff').replaceWith('<div><h2>New heading</h2></div>');
However, how can I get the content from the other view, dynamically and replace it with the div I’ve selected?
Thanks,
jQuery has a convenience method called
load()for this, see http://api.jquery.com/load/ for more informations.In your case, the line would go something like this:
Where
FunnyThings/funviewis the relative URL to your controller.