Skip to content

Instantly share code, notes, and snippets.

@HeinrichApfelmus
Created July 19, 2012 13:42
Show Gist options
  • Save HeinrichApfelmus/3143975 to your computer and use it in GitHub Desktop.
Save HeinrichApfelmus/3143975 to your computer and use it in GitHub Desktop.
Problem with 'POST' ajax request and Scotty-0.4.4
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" /></script>
<script type="text/javascript" charset="utf-8">
// onLoad Handler
$(function () {
$('#form').submit( function() {
$.post('/submit', { x : $('#x').val() }, function (result) {
$('#x').val(result);
});
return false;
});
});
</script>
</head>
<body>
<form id="form" method="post" action ="/submit" accept-charset="utf-8">
<p><input type="text" name="x" id="x" value="21">
<p><input type="submit" id="submit" value="Submit"></p>
</form>
</body>
</html>
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.IO.Class
import qualified Data.ByteString.Lazy as BS
import Web.Scotty as Web
main = scotty 3000 $ do
get "/" $ file "Form.html"
post "/submit" $ do
liftIO $ putStrLn "Showing body contents..."
b <- body
liftIO $ print $ BS.length b
liftIO $ BS.putStrLn b
liftIO $ putStrLn "Retrieving parameter..."
x <- param "x"
let y = 2*x :: Int
json y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment