(eval-when (:compile-toplevel :load-toplevel :execute) (defparameter *dependencies* '(:asdf :hunchentoot :ht-ajax :cl-who :parenscript)) (map nil 'require *dependencies*)) (defpackage :ajax-test (:use :common-lisp :hunchentoot :ht-ajax :cl-who :parenscript)) (in-package :ajax-test) (defparameter *local-dir* "/Users/lucindo/Documents/Lisp/web/3rdparty/") (defparameter *ajax-handler-url* "/ajax") (defparameter *ajax-processor* (make-ajax-processor :type :jquery :server-uri *ajax-handler-url* :js-file-uris "/static/jquery.js")) (defun testfunc (command) (prin1-to-string (handler-case (eval (read-from-string command nil)) (error (c) (format nil "~a" c))))) (defun js () (ps (defun command_clicked () (let ((command (document.get-element-by-id "command"))) (with-slots (value) command (ajax_testfunc_set_element "result" value)))))) (defun main-page () (with-html-output-to-string (*standard-output* nil :prologue t) (:html (:head (:script :type "text/javascript" :src "/js") (:title "AJAX test") (fmt "~a" (generate-prologue *ajax-processor*))) (:body (:h1 "ajax test") (:table :width "50%" (:tr (:td :colspan "2" (:span :id "result" (:i "no results yet")))) (:tr (:td :width "70%" (:input :type "text" :size "70" :name "command" :id "command")) (:td (:input :type "button" :value "eval" :onclick (ps-inline (command_clicked)))))))))) (eval-when (:load-toplevel :execute) (export-func *ajax-processor* 'testfunc :method :post) (setf *dispatch-table* (list 'dispatch-easy-handlers (create-folder-dispatcher-and-handler "/static/" *local-dir* "text/plain") (create-prefix-dispatcher *ajax-handler-url* (get-handler *ajax-processor*)) (create-prefix-dispatcher "/js" 'js) (create-prefix-dispatcher "/" 'main-page)))) (defparameter *webserver* nil) (defun start-web (&optional (port 4242)) (setf *webserver* (start-server :port port))) (defun stop-web () (stop-server *webserver*))