on-the-fly availability for booklists

checkavailI whipped up this proof of concept this week to address a problem with our booklists (and in fact with any lists of books which appear on our website including reviews and new materials lists as well). Booklists are great but what good is a title if it’s not available?

Unfortunately, the booklists are on our website and the availability info is in our catalogue, two different locations entirely. Rigging up a way to automatically load the availability when the booklist loads is not practical as you would need to grab a catalogue page for each title in the list; with many booklists having 20+ titles, that’s a lot of load on the catalogue server.

Instead, I decided to offer on demand lookups using ajax. Even though the booklists app is currently in ColdFusion, I chose to code the backend for this feature in PHP because:

  1. Our inhouse PHP server is simply faster than our shared hosting ColdFusion.
  2. With our ColdFusion site hopefully disappearing in 6 months, I wanted to write something that would be usable on our new site also.

The backend PHP script accepts a bib record number parameter, uses curl to grab the holdings opac page for that title and parses the page to generate a brief holdings summary which is passed back as an html fragment. Once I had that part working, it was time to look at the front end.

Through the jquery plugins site, I found this nice Ajax Tooltip script that looked like it would do pretty much what I wanted. However, at this point I realized my decision to use PHP instead of ColdFusion put me into a situation which seems to happen every time I want to use ajax for something on a site split between 3 servers: cross server security limitations. As with the opac live search, the solution once again appeared to be jsonp. This meant altering the PHP script to embed the html fragment in a json callback as well as altering the tooltip javascript to handle jsonp.

I think it ended up working out pretty well. You can test out the feature here.

4 comments on on-the-fly availability for booklists