Welcome Guest, Not a member yet? Register   Sign In
Populate a view that is already loaded in the controller and the base view
#1

[eluser]sico87[/eluser]
Hello,

I am looking to build a one page website, that runs on PHP(obviously using codeigniter) and AJAX(supported by jquery), at the moment I have a menu that gets populated from the database, depening on what catergories are selected as being on line, the then build a an url using those results,

Code:
if(isset($main_menu)) {
                    foreach($main_menu as $row) {
                        print "<li><a >category_id'>$row->category_name</a></li>";
                    }
                }

My problem is that for this I need to run all the queries from the controller (home) as the user can never leave the page, effectively what I want to happen, is that if the user clicks for example 'Blog', I want a query to run, that selects from the content table in the database all the content that is associated with the blog category I then want to display it in an accordion style, in the 'right-content div' of my site. Then if the the users selects for example inspiration then the query runs again, and adds the inspiration data to same div as the blog data but in its own accordion and not overwriting the blog data.

Is that followable, and more importantly possible, and where the hell would I start, I can use both CodeIgniter and jQuery and really want to push theses technologies and myself.

Thanks
#2

[eluser]rogierb[/eluser]
Take a look at jquery.Ajax().

This is how it works.
* OnClick executes jquery.ajax()
* jquery.ajax() calls a controller like a browser does
* the controller spits out a html page through a view
* In the ajax callback you populate the content div ($("#content").html(callback_html))

Tada!

Just start with a simple ajax calling a controller and echoing one word. Go from there.
You already know how a controller works. Through ajax is work exactly the same only this time ajax is calling the controller, not the browser.




Theme © iAndrew 2016 - Forum software by © MyBB