CodeIgniter Forums

Full Version: JQuery.load() or $this->load->view()
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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!

El Forum

[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');
}

El Forum

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