• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
JQuery.load() or $this->load->view()

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.