0

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?

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

8 Comments

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?
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.
True. But if we let browse limitations hold us back coughIEcough we would still be using CSS1, table layouts and Iframes :)
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.
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.