Ajax Dropdown Example

by frank on September 17, 2006

in Scripts

Ajax Dropdown Example Download.
Everyone knows what Ajax is by now, and there are a slew of libraries and toolkits out there that I mostly have very little experience with but have linked to below because I want to use some of them someday.

AJAX Basics

For those that don’t know AJAX is simply a way of using Javascript to send a request to the server and so incorporating some server side code into your webpage without having to request the whole webpage again.

So, for example, if you had a page which a user interfaced with – you might take some input from the user for a search – then the user would put in their search criteria and then hit a button like ‘Search’. This would submit a form to the server using, say, GET variables, your script on the server would interpret the GET variables and query a database to return some search results to the user.

What AJAX lets us do is query the server with the GET variables the user is inputting into your form, as the user types them. Essentially requesting your search script from the server every time the user types a key without requesting the whole webpage again.

The object that is used in AJAX is the XMLHttpRequest object – however, Microsoft uses a different object like Active X. Which is jolly good of them. So frameworks such as the Dojo Toolkit emerged to abstract the difference between the two objects so that we don’t need to worry if the user is browsing in IE or Firefox etc.

You will see that XML is mentioned in there, it is often returned as the result of your server side search query script, however, JSON (Javascript Object Notation) is very lightweight and easy to deal with, making your applications faster and easier to code essentially.

Enough of the lecture, for this dropdown example I have used a contribution from Michal Migurski, its really straightforward, look through the files in the download. I haven’t exactly IE proofed it so some of the CSS needs tweaking. Change the ajax-query.php file to return results from the database instead of the static array that is in there currently.

Javascript Libraries/Toolkits:

*Note – This example does not work completely – just change the database details for yours to work fully.

Was this article useful?

rss feed icon

Email this article to yourself or...

rss feed icon

Subscribe to the RSS feed for more useful articles and tips.

Share this article with others

  • del.icio.us
  • Twitter
  • Reddit
  • StumbleUpon
  • Facebook
  • Digg
  • http://deadlytechnology.com/scripts/return-json-array-using-ajax-and-prototype/ deadlytechnology.com : Blog Archive » Return JSON array using AJAX and Prototype

    [...] However, I was hunting around and I couldn’t find a decent tutorial on how to return an array of data using prototype’s AJAX functions in JSON notation. There is this one, which was helpful, but it did a lot more than I wanted, and I wanted to use the services_JSON class I used in the ajax dropdown example from an earlier post. [...]

  • http://www.2levelsabove.com ToddF

    Thanks a lot for the informative tutorial.

  • http://www.imagecowboy.com Gino

    Great Solution. A similar effect can be achieved via the following link – i.e. create your own Ajax Drop Down Menu

    http://imagecowboy.com/articles/create_ajax_menu_asp_part1.asp

  • http://www.originalshop.ro Adidas

    Nice tutorial. A good place to start learning these technologies for beginners.

  • http://wikiblast.net/ freemovieblog

    Thats what SHE said!

  • http://top-gear-streaming.blogspot.com TopGear

    Meh, same thing happened to me last time :\

  • vish

    Demo link is not working.

  • frank

    I deleted the old site and some of the links to downloads and demos are not currently working, should be back up soon…

  • frank

    The demo links should be working now.

  • Praveen

    Demo link is still not working

  • SURESHKUMAR P211

    YA DEMO IS NOT WORKING

  • Anonymous

    Sorry about the demo link guys, the download link still works so I would suggest just downloading the files and the demo should run from anywhere really

  • http://www.marfaoriginala.ro Adidasi

    this is gold mine for me!

  • Sourabh