AJAX JSON and Accessibility
Jun 18th, 2008 by Karen
For the last three weeks I’ve been working on creating a prototype of a Wordpress widget which retrieves search results from the WorldCat API and mashes that data up with information from other sources including (LibraryThing, Google Books, Amazon and Open Library). The idea is to create a sidebar listing of books with enhanced information such as covers, and ratings. Really this is an API, mashup experiment to see what is possible. While it does have some practical applications, I haven’t worked out all the “what people would like to see” parts. So I’m playing with demoing the possibilities instead.
The biggest issue I’ve encountered besides fun Terms of Service issues, is that some services make their APIs only available via a client-side JSON call. For me this poses a problem because I work for a state institution which has rules about accessibility that state I have to provide a Javascript alternative. Providing a Javascript alternative isn’t the problem. The issue is providing the best and most equivalent alternative.
The cool thing I found out is that you can parse and handle JSON with PHP. The OpenBook (which use Open Library data) plugin/widget does just this. But the vendor providing the API has to allow this. Both LibraryThing and Google Books’ APIs specifically use language that makes it appear one can only do the JSON call on the client side. Sigh. I understand why this is, but it puts me in the position of providing less than optimal functionality for non-Javascript users.
So for the moment I’m going to code the interface in a less than ideal way. But maybe sometime in the future a better solution will presenter itself or vendors will change them minds.


Heh, if you understand why this is, can you let the rest of us in?
This is continually frustrating to me too, for a variety of reasons. I think I plan to _try_ using the GBS API from the server-side, even though it’s not entirely clear whether Google wants me to or not at present.
Jonathan,
Let me know how that works out. My understanding is that it is limited to client-side for load reasons. I can understand being worried about load issue, but I don’t understand why a client-side script would create less load issues than a server-side script. Any thoughts from others on this?
Is it the TOS for those APIs that limits you to server-side, or simply the inclusion of a javascript wrapper?
[$Gstring contains a well-formed URL]
$G_json = file_get_contents($Gstring);
echo $G_json;
$G_json = str_replace(”var _GBSBookInfo =”,”",$G_json);
$G_json = str_replace(”;”,”",$G_json);
$G_json = str_replace(”\\x26″,”&”,$G_json);
$G_json = trim($G_json);
$value = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$G_data= $value->decode($G_json);
foreach ($G_data as $v1)
{
if($v1['preview'] == “full” && strlen($v1['thumbnail_url']) > 1)
{
echo “\r\n\r\n\r\n\r\n”;
}
else if($v1['preview'] == “partial” && strlen($v1['thumbnail_url']) > 1)
{
echo “\r\n\r\n\r\n\r\n”;
}
}
It’s a mess, but it handles GBS on the server side…
My bad -
Scratch the “echo $G_json;” — For a funny reason, I do some processing on the server side, then handle markup and presentation with client-side scripts. The code below it was commented-out.
Also, it looks like my html markup got eaten.
Anyway, you can do most anything with SimpleXML easier, so if they expose an XML API, that’s probably the way to go.