Online Book Reader

Home Category

AJAX In Action [245]

By Root 4056 0
named q in the querystring. If one exists, it parses the value of the parameter and places it into the lookup field. Then, it simply initiates a search via the doSearch() method. Mystery solved.

12.6.3 Refactoring debriefing

Let’s take a moment to consider what we’ve accomplished so far. We’ve written a helper class called XSLTHelper, which encapsulates the hard-earned knowledge of providing XSLT support on the browser client. We’ve taken advantage of that helper in our live search component. We’ve written a simple yet generic configurable live search component that can take just a few pieces of information and transform the user’s web page into a responsive searching animal. We’ve written our component in a clean OO style that exemplifies simple design and separation of responsibilities. Overall, not bad for a day’s work.

12.7 Summary

In this chapter, we took a basic search page and added Ajax functionality to it. The search allows the process to flow so that we can control the window while the server-side process is taking place. This means that we are able to place an animation in the browser. Having control of the browser allows us to perform other operations so we can make sure that the users of the application know that their search is taking place.

We then implemented XSLT processing to transform our XML document into formatted HTML code, which we applied to our div element’s innerHTML property. This let us avoid using JavaScript to dynamically loop through the XML

nodes and build a large string to apply to the document. Instead, we could rely on XSLT to produce the document from the XML.

Just because we used the processing animation and the XSLT with the live search does not mean we cannot apply these concepts to other projects. We can easily add this capability to a normal transaction with the server. I always hear people say that they have a process that takes several minutes to complete. Is there a way to show a message? We can easily use the innerHTML property that we used in this project to add an image or message telling the user that the processing of the search is under way. With almost every Ajax application, we should show that an action is taking place so the user does not repeatedly click the submit or the refresh buttons. Licensed to jonathan zheng

502

CHAPTER 12

Live search using XSLT

We can use XSLT to style RSS feeds or to change any of the other projects that we have done by using XSLT instead of performing the XML DOM looping on the client.

In the four examples that we’ve developed so far, we’ve implemented our own server-side processes specifically to serve our Ajax clients. In the final chapter, we’ll look at an Ajax client that communicates directly to an Internet standard web service: an RSS news syndication feed.

Licensed to jonathan zheng

Building stand-alone

applications with Ajax

This chapter covers

Handling RSS feeds

Ajax for accessing websites directly

Ajax without a server

Fade-in, fade-out

503

Licensed to jonathan zheng

504

CHAPTER 13

Building stand-alone applications with Ajax

In the last four chapters, we’ve developed a range of neat Ajax applications and shown the client-side and server-side code for each. In this chapter, we don’t need to present you with any server-side code, because we’re not going to write any. This may come as a surprise to most people, but we can run Ajax applications directly against any web server-based stream of data, including those that are generated by third-party applications. We can develop a rich user interface for a web page that acts like a client application.

Many websites offer XML feeds in the formats of Really Simple Syndication (RSS), Resource Descriptor Framework (RDF), or Atom, which are the three most common syndication feeds that we see. The information contained in these syndication feeds can be daily news articles, comics, weblogs ( blogs), jokes, weather, and so on. With Ajax we have the ability to get the syndication information without

Return Main Page Previous Page Next Page

®Online Book Reader