MFlow- Web app server for stateful processes with safe, composable user interfaces.

Safe HaskellNone



A very simple (but effective) support for AJAX. The value of a javaScript variable is sent to the server. The server must return a valid sequence of javaScript statements that are evaluated in the client.

This example increase the value, from 0 on, in a text box trough AJAX:

 import Text.XHtml
 import MFlow.Forms
 import MFlow.Forms.Ajax
 ajaxsample= do
   ajaxheader html= thehtml << ajaxHead << html
   setHeader ajaxheader
   ajaxc <- ajaxCommand "document.getElementById('text1').value"
                           (n ->  return $ "document.getElementById('text1').value='"++show(read n +1)++"'")
   ask $ (getInt (Just 0) <! [("id","text1"),("onclick",ajaxc)])





:: MonadIO m 
=> String

The javScript variable whose value will be sent to the server

-> (String -> IO String)

The server procedure to be executed with the variable value as parameter. It must return a string with valid javaScript code to be executed in the client

-> m String

return the javascript of the event handler, to be inserted in the HTML to be sent to the client

Install the server code and return the client code for an AJAX interaction.

ajaxHead :: Html -> HtmlSource

ajaxHead must be used instead of header when using ajax(see example).

Although it produces code form Text.XHtml rendering (package xhtml), it can be converted to byteString, so that any rendering can be used trough normalization . see setHeader