I''m working on new methods of doing Ajax calls through streaming
responses. I''ve created a little javascript library (which depends on
prototype.js) that can interpret a stream of JSON objects separated by
semicolons.
As an application of this, this Mongrel plug-in streams upload status
when given a qualified upload_id. It looks like this:
{"received":5939792,"status":200,"state":"uploading","size":36872784};
{"received":6398544,"status":200,"state":"uploading","size":36872784};
[...]
{"received":36479568,"status":200,"state":"uploading","size":36872784};
{"received":36856400,"status":200,"state":"uploading","size":36872784};
{"received":36872784,"status":200,"state":"done","size":36872784};
(The format of these JSON objects is the same that is being used in
the upload progress plug-in for Lighttpd 1.5 as described at
http://trac.lighttpd.net/trac/wiki/Docs:ModUploadProgress )
Included with this package is the javascript library Ajax.Pull, and an
example Rails application.
http://s3.amazonaws.com/four.livejournal/20070708/mongrel_streaming_upload_progress-0.2.gem
http://s3.amazonaws.com/four.livejournal/20070708/mongrel_streaming_upload_progress-0.2.tgz
This should work with Safari 3 and Firefox. I haven''t tested IE.
(When I get around to it will add a hack to Ajax.Pull which falls back
on polling a URL for the JSON updates if the browser does not support
Ajax streaming. This plug-in already supports this sort of polling
with the ?single=true URL parameter.)
ry