[hunchentoot-devel] ht-simple-ajax

Haris fbogdanovic at xnet.hr
Wed Apr 6 14:21:30 UTC 2011


Here I changed the function names to reflect the code:

-------------------------------------------------------------------------------

(defpackage :sessions (:use :cl :hunchentoot :cl-who :parenscript
:ht-simple-ajax))

(in-package sessions)

(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"))

(push (create-ajax-dispatcher *ajax-processor*) *dispatch-table*)

(defun-ajax show-x () (*ajax-processor*)
  (write-to-string (incf (session-value 'x))))


(define-easy-handler (main-page :uri "/") ()
  (start-session)
  (setf (session-value 'x) 10)
  (with-html-output-to-string (*standard-output* nil :prologue t :indent t)
    (:html :xmlns "http://www.w3.org/1999/xhtml"
     (:head
      (princ (generate-prologue *ajax-processor*))
      (:script :type "text/javascript"
       (str
        (ps

        (defun show-x ()
          (alert (ajax_show_x))))))

     (:body
      (:p (:a :href (ps-inline (show-x)) "Show X"))))))










More information about the Tbnl-devel mailing list