CodeIgniter Forums
JQuery.load() or $this->load->view() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: JQuery.load() or $this->load->view() (/showthread.php?tid=52732)



JQuery.load() or $this->load->view() - El Forum - 06-24-2012

[eluser]peekk[/eluser]
Hello, I have a few views in divs loaded on my page.

and I have something like that:

Code:
<div id=header>
...
...
</div>

<div id=content>
...
...
...
<a href="#" class="ref"> refresh extra div </a>

<div id=extra>
&lt;?php $this->load->view('extra.php'); ?&gt;
</div>
....
....
...
</div>


<div id=footer>
...
...
</div>


Now I want to refresh my #extra div after some action, for example clicking on the "refresh extra div" link.

I was trying to use jquery in a way:
Code:
$(".ref").click(function() {    
$('#extra').load(&lt;?php $this->load->view('extra.php'); ?&gt;);
});

but it doesnt work - how to do it? How to dynamically refresh divs which views?

Thanks!


JQuery.load() or $this->load->view() - El Forum - 06-24-2012

[eluser]PhilTem[/eluser]
You need to perform an AJAX-Request when somebody clicks on the div or the link. The action therefore (the argument of the 'load()' function) must be an url to a page that has only the content you want to have as replacement for your old content.

It should be something like this

Code:
$('#extra').load('test/ajax_refresh');

And your controller "test" with method "ajax_refresh" would look like
Code:
function ajax_refresh()
{
  $this->load->view('extra');
}



JQuery.load() or $this->load->view() - El Forum - 06-25-2012

[eluser]peekk[/eluser]
Simply brilliant, thank you!: )