[hunchentoot-devel] ht-simple-ajax
Haris
fbogdanovic at xnet.hr
Sun Apr 3 14:37:31 UTC 2011
Here is the complete code,
(I start Hunchentoot from REPL and use parenscript)
(defpackage :ajax (:use :cl :hunchentoot :cl-who :parenscript
:ht-simple-ajax))
(in-package ajax)
(setf *access-log-pathname* "c:/lisp/hunchentoot-log/access.log")
(setf *message-log-pathname* "c:/lisp/hunchentoot-log/message.log")
(setf *js-string-delimiter* #\")
(defparameter *ajax-processor*
(make-instance 'ajax-processor :server-uri "/ajax"))
(defun-ajax say-hi (name) (*ajax-processor*)
(concatenate 'string "Hi " name))
(define-easy-handler (main-page :uri "/") ()
(with-html-output-to-string (*standard-output* nil :prologue t :indent t)
(:html :xmlns "http://www.w3.org/1999/xhtml"
(:head
(:title "ht-simple-ajax demo")
(princ (generate-prologue *ajax-processor*))
(:script :type "text/javascript"
(str
(ps
(defun callback (response)
(alert (@ response firstChild firstChild nodeValue)))
(defun sayHi ()
(ajax_say_hi (chain document (getElementById "name") value)
callback))))))
(:body
(:p "Please enter your name: "
(:input :id "name" :type "text"))
(:p (:a :href "javascript:sayHi()" "Say Hi!"))))))
More information about the Tbnl-devel
mailing list