You are looking at historical revision 13621 of this page. It may differ significantly from its current revision.
This extension provides a set of procedures to use asynchronous callbacks from a browser to a Chicken-powered web-server (for example Spiffy). This is done using Prototype's wrappers around the xmlHttpRequest API.[parameter] (ajax-output-format [SYMBOL])
Specifies how HTML and script-fragments generated by the procedures of this package should be handled. SYMBOL should be either shtml or html, where the former requests output as SXML expressions and the latter as text containing HTML. html is the default.[parameter] (ajax-callback-registration [PROCEDURE])
Holds a procedure that will be called for every registered xmlHttpRequest callback (see below).[procedure] (ajax [KEY [SCRIPTFILENAME]])
Initializes callback handling for this page/response and returns a HTML or SHTML fragment containing a script element linking to the given source filename, which defaults to prototype.js. The Prototype library is included in the distribution and will be installed in the extension repository.
The optional argument KEY is used to make the generated callback-URLs for this page more unique and may be an arbitrary string.
This procedure resets the callback-handling for this response and must be called before using any of the remote-... procedures described below.[procedure] (remote-url THUNK [ARGUMENTS] [SESSIONID] [UNIQUEID] [LIFETIME])
Registers a HTTP callback handler for a generated URL that invokes THUNK, a procedure with no arguments. If ARGUMENTS is given, then it should be a string or an association-list mapping URL-encoded argument-names to values. In both cases the arguments will be encoded in the url. If SESSIONID and LIFETIME are given, this url will be expired when the LIFETIME in seconds is passed from the last access of urls with the SESSIONID. If UNIQUEID is given and not #f, it is used to remove the previous url with the same UNIQUEID.
This procedure returns an URL as a string.[procedure] (remote-action THUNK #!key arguments update insert-before insert-after insert-top insert-bottom method success failure name frequency eval-scripts sessionid uniqueid lifetime)
The meaning of the various keyword arguments is as follows.
- A string or an association list of URL-encoded variable/value pairs (see remote-url for more information)
- the id of a document node that should be replaced with the SXML of this reply
- Document-id of element before which the reply will be inserted
- Document-id of element after which the reply will be inserted
- Document-id of element in which the reply will be inserted as the topmost sub-element
- Document-id of element in which the reply will be inserted as the bottommost sub-element
- HTTP request method used
- The interval in seconds after which the callback should be invoked
- Pass to remote-url
- Pass to remote-url
- Pass to remote-url
Returns HTML or SHTML for a link (<a>) that will invoke THUNK when clicked. The KEYWORD-ARGUMENTS are the same as for remote-action.[procedure] (remote-button TEXT THUNK KEYWORD-ARGUMENTS ...)
Returns HTML or SHTML for a button (<button>).[procedure] (remote-timer FREQUENCY THUNK KEYWORD-ARGUMENTS ...)
Disables caching of the current page by setting various HTTP response headers. Handy for debugging.
Here we use the ajax extension in an ssp page:
<!-- test.ssp --> <html> <head> <?scheme (use ajax) (no-cache) (display (ajax)) (define words '(one two three)) ?> </head> <body> The current time is: <span id="time"><b>...</b></span> <p> <ul id="list"></ul> <p> <? (remote-timer 2 (lambda () (printf "<b>~a</b>" (seconds->string (current-seconds)))) update: "time") ?> <p> <? (remote-button "Click me" (lambda () (printf "<li>~a</li>" (list-ref words (random (length words))))) insert-bottom: "list") ?> </body> </html>
To try it out you can invoke csi like this (assuming prototype.js and test.ssp are in the current directory):
$ csi -q #;1> (use spiffy ssp-handler) #;2> (spiffy-file-ext-handlers `(("ssp" . ,ssp-handler))) #;3> (start-server port: 8080 root: "." debug: #t)
- 1.8.1 Explicit use of SRFI 69 [Kon Lovett]
- 1.8 Fix for Ticket #315
- 1.7 session support [Daishi Kato]
- 1.6 Added key parameter to ajax
- 1.5 Removed quoting from remote-action argument parameter
- 1.4 Updated prototype.js to version 1.4.0
- 1.3 Fixed bug in handling of 'parameters' keyword arg
- 1.2 Several enhancements by Daishi Kato
- 1.1 Bugfix in remote-button by Daishi Kato; current-request and current-urlencoded-arguments are now also available in callbacks
- 1.0 Initial release
Copyright (c) 2005-2008, Felix Winkelmann and Mario Domenech Goulart. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.