Created
July 19, 2012 13:42
-
-
Save HeinrichApfelmus/3143975 to your computer and use it in GitHub Desktop.
Problem with 'POST' ajax request and Scotty-0.4.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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