snap-extras-0.9: A collection of useful helpers and utilities for Snap web applications.

Stabilityexperimental
MaintainerOzgun Ataman
Safe HaskellNone

Snap.Extras.Ajax

Description

Simple combinators to work with AJAX requests.

Synopsis

Documentation

replaceWithSource

Arguments

:: MonadSnap m 
=> Text

jquery selector

-> ByteString

content blob

-> m () 

Replace innerHTML of given selector with given conntent.

replaceWithTemplateSource

Arguments

:: HasHeist v 
=> ByteString

Heist template name

-> Text

jQuery selector for target element on page

-> Handler v v () 

Replace the inner HTML element of a given selector with the contents of the rendered Heist template.

Currently expect you to have jQuery loaded. TODO: Make this jQuery independent

data ResponseType Source

Possible reponse types we support at the moment. Can be expanded for more use cases like JSON, CSV and XML.

Constructors

Html 
Ajax 

respond :: MonadSnap m => (ResponseType -> m b) -> m bSource

The multi-mime dispatcher. It will inspect the Accept header and determine what type of a request this is. If AJAX, make sure to set the Accept header to 'application/javascript'.

responds :: MonadSnap m => [(ResponseType, m b)] -> m bSource

Dispatch on all response types

htmlOrAjaxSource

Arguments

:: MonadSnap m 
=> m b

If call is HTML

-> m b

If call is AJAX

-> m b 

Classic pattern of responding to a static HTML or an alternative AJAX request.