[hunchentoot-devel] ht-simple-ajax
Andy Peterson
andy.arvid at gmail.com
Sun Apr 3 15:31:37 UTC 2011
I see two problems:
1. You do not inform Hunchentoot about your ajax-dispatcher you need
to add this:
(setq *dispatch-table* (list 'dispatch-easy-handlers
(create-ajax-dispatcher *ajax-processor*)))
above as in the example of ht-simple-ajax.
Instead, I normally use:
(push (create-ajax-dispatcher *ajax-processor*) *dispatch-table*)
2. Do not use camel-case in parenscript. Parenscript is not
case-sensitive. Parenscript uses the lisp standard of hyphens which
translates to the javascript standard camel-case.
AJAX> (ps getElementByID)
"getelementbyid;"
AJAX> (ps firstChild)
"firstchild;"
AJAX> (ps get-element-by-id)
"getElementById;"
AJAX> (ps first-child)
"firstChild;"
Similarly See also "sayHi" and "nodeValue"
On Sun, Apr 3, 2011 at 10:37 AM, Haris <fbogdanovic at xnet.hr> wrote:
> 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!"))))))
>
>
>
> _______________________________________________
> tbnl-devel site list
> tbnl-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/tbnl-devel
>
More information about the Tbnl-devel
mailing list