CloServe A view first web framework in Clojure

Return JS cmd result to server

Return JS Cmd Result to Server Example

Use query.ajax snippet to send a js cmd to browser, browser eval this js cmd, and send the result back to server. Server than invoke a call back function.

With this example callback function:

 [context cmd]
 (send-cmd-to-page (:page-id context)
                     {:act :append
                      :selector (str "#msgww" )
                      :html (str "Browser window width is " cmd)

and the following HTML code, $(window).width() cmd will be send to browser, the server will then process the return with callback function

<span class="lift:query.ajax?callback=EchoQuery;code=%24(window).width()"></span>