Ajax is sexy and I love it. So is JSON, but I’m weird that way. JQuery – has its uses, but it reminds me too much of the dark arts and people prancing around campfires in the forest at midnight.
Pros & Cons of Ajax Implementation
- Pro: You get access to live data.
- Pro: Faster page load if there is a lot of data
- Pro: Very sexy when you tell the client about it.
- Con: Slowdown in internet connection can disrupt the process.
- Con: A server with a heavy load can be slow in delivering a response.
- Pro: Auto-complete is very responsive, very fast.
- Pro: Does not rely on the speed of internet connectivity.
- Pro: Does not get bogged down by a heavy server load.
- Con: Slower page load for a lot of records (we’re talking a couple thousand or more)
- Con: That feeling when the client asks if you are using ajax.
Making the choice
Auto-complete example (Example)
So you have a form where a person is entering month names (or names of people, or names of businesses, or their favourite Klingon hottie) and you want to offer auto-complete. We all know how tough those Klingon names are to remember.
Here is the implementation using my autocomplete.js library.
|Try out auto-complete with month names and Klingon hotties.|
My auto-complete JS file makes it easy-peasy to add this feature. Here is a break down of what you can do:
Instantiate the object to a new file handle
var objHandle = new autocomplete();
Pass the array of search terms to the object
Add individual terms to the array
var name = 'My Name'; objHandle.addWord(name);
Remove a term from the object
var removename = 'My Name'; objHandle.removeWord(removename);
Make the search terms case-insensitive (recommended).
Make the search terms case-sensitive (default).
Count the number of terms in the object
var wordCount = objHandle.count();
Extract the list of terms in the object
var wordsInList = new Array();
wordsInList = objHandle.list();
Trigger autocomplete form a text/textarea field
Note that “this” and “event” are static arguments, they never change no matter how many objects you have on the page.
|This page has all of the auto-complete features for you to try out.|
Creating the above code from Perl
Didn’t think I’d forget about that, did you? Here is some code that you can use to generate the data array and code needed for the web page. All you have to do then is add the object instantiation and object handle. This example uses a MySQL call to assemble the data:
|Perl library init_autocomplete.lib|
Now go, code, be happy. 🤓