Ajax + Database content |
[eluser]stuffradio[/eluser]
Has anyone done one of those AJAX tab things where you click a link and it switches the content in a div? If so, how did you do it where you switched it and when you switch it there are different results from the db using models? I'm basically asking how I should pass results from models so I can load them in the div tag with ajax
[eluser]WebsiteDuck[/eluser]
If you're using a JS user interface framework like jQuery UI, they have a tab widget that does ajax automatically. If you're using jQuery but not jQuery UI, you'll have to set up a callback like Code: $(".my-tabs").click( function() { And then you would create a get_tab method in your controller that interfaces with the model and then either echos the data out or calls a view. The tab id will be available in $this->input->post('tab') If you're not using jQuery then you'll have to do the ajax stuff yourself, and set up a function thats called in the onclick of your tabs, which will be a ton of fun.
[eluser]vitoco[/eluser]
The model only retrieve the data from the storage device ( mysql database, text files ) to the controller...and this one, handle the data to retrieve it to the client browser throught view. So, to load content ( a DIV ) with ajax, you must call a controller/method like this http://domain.com/controller/method/param1/.../param2 Inside the controller/method, you must load the model to retrieve the data , and then send it to the client browser in a view. Code: ... This is the server side, the client side was explained before with an jquery example.
[eluser]stuffradio[/eluser]
I know the model only retrieves data, I already know about models and databases and fetching data and how to pass it to a view, I was only wanting to know about AJAX and getting data with AJAX. @WebsiteDuck I'll try it later, thanks
[eluser]stuffradio[/eluser]
Haven't tried WebsiteDuck's solution yet, I will let you know if I still need help
[eluser]vickel[/eluser]
@ websiteduck change the line Code: $.post("<?=base_url()?>home/get_tab", to Code: $.post("<?=site_url()?>/home/get_tab", |
Welcome Guest, Not a member yet? Register Sign In |