AJAX Ideas
I mentioned a while ago that one idea I've liked for years is the idea of using JavaScript as a data-transfer medium. While it's a little scary to think of accepting executable code from a server (Ok, really scary), I keep coming back to the idea. So it may be a bad idea, but it's an attractive idea. Let me indulge in a little out-loud thinking at least. Let's take the NewsGator API as a source for data. NG has the idea of Locations, which are one way to organize subscriptions. The idea is that you might have "Home" and "Work" locations, and each has a separate subscription list, but these have some feeds in common. Let's look at the output from a GetLocations call, which
<ArrayOfLocation xmlns="http://services.newsgator.com/svc/Location.asmx"> <Location> <id>1</id> <name>Home</name> <autoAddSubs>false</autoAddSubs> </Location> <Location> <id>2</id> <name>Work</name> <autoAddSubs>false</autoAddSubs> </Location> <Location> <id>3</id> <name>NewsGator Web Edition</name> <autoAddSubs>true</autoAddSubs> </Location> </ArrayOfLocation>
So, I've got 3 locations. As it stands now, I'd go through some sort of XML->JavaScript conversion to arrive at something like this:
function nglocation(id, name, autoadd) {
this.id = id;
this.name = name;
this.autoAddSubs = autoadd;
}
var locations = [ new nglocation(1,"Home",false),
new nglocation(2,"Work",false),
new nglocation(3,"NewsGator Online Edition",true) ];
I'm hand-waving at the XML to object conversion, but it's straightforward. My thought here though, is that it's unnecessary. Why not have the server just return JavaScript? I think that you'd probably end up downloading a script library to contain the nglocation declaration and then retrieve the data using XmlHttpRequest. So you'd download something like the var locations declaration, at least the part right of the equal sign. Once you've got that, I suppose you'd feed the result of the call to eval, which is where it gets scary. eval is frightening in many ways, it's sort of the goto of dynamic languages. But assuming you trusted the source of the data (I know, I know), it would make implementing a client somewhat easier, assuming your client environment understood JavaScript.