Chapter 10. Type-ahead suggest

 

This chapter covers

  • Type-ahead suggest
  • Caching search results on the client
  • Rico library
  • Prototype library
  • JavaScript apply() function
  • Parameterizing components

Type-ahead suggest is one of the main applications of Ajax that has helped put Ajax into the mainstream world of programming. Google Suggest amazed people as they discovered a list of choosable suggestions appearing while they were typing (and even now, several months later, it still gives a buzz). It is as if a little helper is sitting next to you and telling you what you are looking for. Some people first thought they were storing values on the page, and others thought they were using a hidden IFrame to get the data. Google was actually using the XMLHttpRequest object to obtain the values for each keystroke.

In this chapter, you’ll learn how to send Ajax requests while the user is typing. We also examine the flaws of the available type-ahead suggest implementations and find ways to avoid these pitfalls in our application. At first we take a low-level approach that is easy to understand. After we get our application functioning, we reexamine it at a higher level, and use an object-oriented approach to gain more flexibility and usability. Before we build the application, though, let’s take a quick look at some of the typical type-ahead suggest features, and how we will design our application to use the best of those features.

10.1. Examining type-ahead applications

10.2. The server-side framework: C#

10.3. The client-side framework

10.4. Adding functionality: multiple elements with different queries

10.5. Refactoring

10.6. Summary