views:

109

answers:

1

I am currently building a website in codeigniter that is one page site, basically one the user comes to the page, they created with a main menu from that menu they choose which sections of the sites they would like to see, and clicks on the associated links...clicking on these links should display the content in their own accordian menu.

My question is I assume the easiest way to do this would be load the selected views in using jquery and ajax? If I am on the wrong lines what would be a better solution, also I can't find anything about loading in views using ajax, does any one have any advice?

Thanks Very Much

+5  A: 

Yes, you can easily load content with AJAX and jQuery, by binding click-events on your menus and links, like this:

$("a.menuitem").click(function () {
    var link = $(this), url = link.attr("href");
    $("#content_pane").load(url);
    return false; // prevent default link-behavior
});

However, by going down this route you forego some key functionality in the browser. The Back-button won't work. Your users can't bookmark any of the subpages. There are workarounds (like this jquery history plugin), but it'll be a lot of work to replace functionality that comes natively with every users browser.

Magnar
Thanks for that I have tried to implement this, but it just navigates me to a new page rather adding the content to the current screen any ideas?
sico87
If you implement this just as written, you also need to make sure that the links have the class "menuitem", and that your current screen has an element with the id "content_pane". It's more of an example than a ready-for-production codesnippet.
Magnar
True. But if we let browse limitations hold us back *cough*IE*cough* we would still be using CSS1, table layouts and Iframes :)
Atli
True that, but I wouldn't call the Back Button or Bookmarks a limitation of the browser. There is a sweet spot for utilizing AJAX, and this is a good deal beyond that spot in my opinion.
Magnar
Capabilties of not bookmarking and no back button have been thought, and for the target audience of the website and what the website is trying to achieve is the perfect solution.
sico87
I have both the selectors in my html, still nothing I can follow the code perfectly no exactly what it is doing, and I see know reason that it should not work.
sico87
I can take a look at it if you have an URL to the page in question.
Magnar
Thanks got it working I was being a moron, I had put it outside my document ready definition, so obvioulsy it wasnt going to work, thanks for your help.
sico87