Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-29-2007, 08:56 PM   #1
Registered: Oct 2006
Distribution: Ubuntu 6.10
Posts: 59

Rep: Reputation: 15
Good Ajax Code Examples

Hey all I have been looking around the net trying to find some good Ajax examples for my senior project. And I cannot for the life of me find what I am looking for.

Basically what I want to do is make a webpage that searches a Database. The page will start off with 5 basic categories, which will be links. What I want to happen is when you click on a link it generates another menu or portion of the website, maybe a div or a table row, with the sub categories of the main categories under it. And you click it again to get the sub categories of the sub categories. If this does not make sense here is a picture

Winter   Climbing   Camping   Water   Misc
Then the user clicks on Winter and the page adds...
Winter   Climbing   Camping   Water   Misc
Telemark   Alpine   Snowboard
Then the user clicks Alpine and the page adds...
Winter   Climbing   Camping   Water   Misc
Telemark   Alpine   Snowboard
Skis   Boots   Poles   Equipent
The clicks boots and the page generates a small form to get the size of the person and then performs a search on it. All of this is done without reloading the page.

In order to generate the various sub menus the webpage hits a database to get the unique categories.

Any help with this would be greatly appreciated.
Old 03-30-2007, 02:05 AM   #2
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,550

Rep: Reputation: 137Reputation: 137
if you want to connect to a database you may choose a script language first that gives you this ability like perl, php, python...
You wont need a database to change the variuos navigations according to a clicked topic. 1 of the languages mentioned above will do - or javascript.

In respect of AJAX keep in mind that still a lot of fellows are surfing the web with deactivated javascript. There's no AJAX then.
Old 03-30-2007, 12:24 PM   #3
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint
Posts: 9,716

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
have a look at this AJAX framework, jMaki:
Old 04-09-2007, 04:02 PM   #4
Registered: Sep 2004
Location: UK
Distribution: Ubuntu
Posts: 117

Rep: Reputation: 16
All AJAX really means is to pull a page from a server without requiring a refresh of the whole page. Then using JavaScript you can insert the resulting content into a HTML element.

You can have something like:
<div id="categories">Winter Climbing Camping Water Misc</div>
<div id="manufacturers"></div>
<div id="items"></div>
<div id="form"></div>

The items in categories would be links to a JavaScript which would pull the manufacturers details down, and then insert them into the manufacturers div. This would be a series of links generated to link to the JavaScript to fill the items div, which would do the same for the form div.

I think this is the sort of thing you want, if it is you can either search the web for simple AJAX functions or I can post the code I use for things like that. As J-Ray said, if the user has JavaScript disabled then this will not work, and you simply wont get a response. I don't know of anyway of making AJAX based sites degrade well. And as J-Ray said again, you would need to code the pages that you are retrieving in PHP, or a similar language that supports databases.
Old 04-09-2007, 04:11 PM   #5
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Yea, AJAX is nothing more than a set of technologies working together. They are the browser + JavaScript (on the client), and some programming (on the server side). For large sites, the programming on the server side gets its data from a database. The great thing about this model is that all the pieces are (supposedly) completely isolated. The browser doesn't matter, as long as it supports version whatever of JavaScript. This is completely disconnected from the server, which could be running Perl or Python or Ruby or C or Erlang or Scheme or who-cares-whatever. And the database doesn't matter as long as your language of choice can access it. So to do AJAX you really need to know about four different technologies, most likely, and how they inter-relate and communicate with one-another.
Old 04-09-2007, 04:17 PM   #6
Registered: Sep 2004
Location: UK
Distribution: Ubuntu
Posts: 117

Rep: Reputation: 16
Further to my last post, I see no reason why you couldn't generate nested divs, so you would start with:

<div id="categories">Winter Climbing Camping Water Misc</div>
<div id="stuff"></div>

The categories would then insert the HTML into the 'stuff' div, but would insert:
<div id="manufacturers">Telemark Alpine Snowboard</div>
<div id="items"></div>

Seems a little more complex, and may not be ideal...I don't know, but I can't see why it wouldn't work. I would appreciate some input if I am wrong though.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Cuba and Venezuela - Unlikely Good Examples of Open Source Preference LXer Syndicated Linux News 0 02-21-2007 05:16 PM
Where to find a server-side php code that interacts with Ajax? Basel Programming 2 02-05-2006 06:11 AM
XML Code Examples FLLinux Programming 1 01-17-2006 02:21 AM
Anyone know where I could get some good examples of sendmail files? WorldBuilder Linux - Networking 1 05-14-2003 05:12 AM
Looking for a good list of shell commands with examples jk1 Linux - Newbie 4 06-11-2002 09:09 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration