Ruby on Rails
XmlHTTPRequest

(Note this needs massive cleanup I rescued it from the PDX Wiki Mirror)

Concept
Xml HTTPRequest is the technology behind Gmail, google-groups2, http://Flickr.com, http://A9.com (amazon) and many other services.

It allows data passing between the browser and the server without reloading the page, thus giving the user a much better experience. think of building a find-as-you-type service, a live Chat without page reloading, automatic fast visualization for online WYSIWYG stuff, dynamic extension of the page and so on.

It is basically some client side javascript to be interfaced with some server side code.

It would be great if Rails could provide something (possibly as simple as an helper) to allow easy bridging.

It is supported in Konqueror/Safari, Firefox, Mozilla, IE6, and in the next opera release (see \here\). It is clearly a direction where the market is heading.

Other Implementations
For examples and docs in other languages see:
http://jpspan.sourceforge.net (php)
(edit) jpspan\’s implementation is very slick using reflection on php classes to autogenerate the corresponding java script methods almost seemlessly. Probably some reusable code, especially in the \PostOffice class\

And the files \liveevil.py and liveevil.js\ (python).

For a ruby sample see \CROS by SimonStrandgaard\

Very \simple XUL example\
To get it to work with mysql, simply change database.yml appropriately, and create the two tables.
It\’s just the basic demo from O\’Reilley (same two tables), with just list.rhtml and sort.rthml having the XUL mods, which you could get from the directory listing (recipes/views/list.rhtml and recipes/views/show.rhtml).

\‿\Sajax\ is a tool to make programming websites using the Ajax framework — also known as XMLHTTPRequest or remote scripting — as easy as possible. Sajax makes it easy to call PHP functions from your webpages via Java Script without performing a browser refresh. The toolkit does 99% of the work for you so you have no excuse to not use it.\‿

Used like:
  1. PHP Code
    function multiply(x, y) { return x * y;
    }
    rs_init();
    rs_export(\”multiply\”); // list of functions to export
    rs_handle_client_request(); // serve client instances
    Related
    rubyish extensions to javascript:
    http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/117184
    ruby-ish extensions to javascript i use: array.each, array.each_index, object.each_slot etc etc.

Serialization using JSON (see http://json-rpc.org) seems to fit best IMHO.

Discussion
Avi Bryant talks about this related to his Seaside2 web framework \here\
and from the trackback you can get \this page\ (liveupdate.rb for usage with Borges, maybe easy to port)

I\’ve implemented a reasonably good working Request object using iframes, might be of interest. -Alwin

Something like this would also be incredibly useful

towards creating XUL helpers (radio, checkbox, menudropdown and friends)
towards allowing eager updates (document script receives event whenever a registered child element that has a db mapping changes, script updates db appropriately quietly and cleanly unless error occurs (let\’s hear it for getting rid of input fgbbbf bbbbbbbbbbbb ggtype=\‿submit\‿))
towards allowing lazy updates, which would be exactly like eager, except updating every x changes (or y condition), and would require the script to fire on the document onclose event.. and would probably also require the controller to hold the data in case of error, since the view has been destroyed, and do something nifty with it to tell client that their update blew up. —GJW
\XmlHTTPRequest will play a role in the next version of ruby-doc, due Real Soon Now (AKA when I get through all the work that manages to pay my bills. It\’s quite slick but work has slowed.) —James Britt

Ajax Discussion is where discussion of the Ajax functionality is discussed..

Resources
DEAD LINK \Combining XMLHttpRequest and Rails to Produce More Efficient UIs\ – how to implement a method of editing line-items directly in a list, using Rails, \JavaScript and \XmlHttpRequest, by Dave Goodlad
DEAD LINK \Useful Javascript Tools for Railers\
\Ajax: A New Approach to Web Applications\
\Ajax working examples\
\Basic information on how to use XMLHttpRequest\ – From Apple Developer Connection but applicable to all browsers and platforms, except the example code download which is in DMG format.

See also: