UNPKG

page.js-body-parser.js

Version:

Plugin for page.js which implements support for forms akin to body-parser.

69 lines (60 loc) 1.9 kB
<!DOCTYPE html> <html> <head> <title>Simple sample app to test page.js-body-parser.js</title> <meta charset='UTF-8'> </head> <body> <ul> <li><a href='/testlink'>/testlink (test of a regular link)</a></li> </ul> <form action='/bodytest' method='post'> <fieldset> <legend>body test</legend> <dl> <dt><label for='textbox'>text box:</label></dt> <dd><input type='text' name='textbox' id='textbox'></dd> <dt><label for='checkbox'>checkbox:</label></dt> <dd><input type='checkbox' name='checkbox' id='checkbox'></dd> <dt><label>radios:</label></dt> <dd> <ul class='radios'> <li><input type='radio' name='radios' value='one'> one</li> <li><input type='radio' name='radios' value='two'> two</li> <li><input type='radio' name='radios' value='three'> three</li> </ul> </dd> </dl> <div class='actions'> <input type='submit' name='submit' value='Submit'> </div> </fieldset> </form> <p><em>Note: this can only be run from a web server. If you have Python installed, you can start a quick one by running "<code>python -m SimpleHTTPServer</code>" and then going to <a href='http://localhost:8000/sampleApp.html'>http://localhost:8000/sampleApp.html</a>.</em></p> <!-- make sure to run: bower install page.js --> <script src='bower_components/page.js/page.js'></script> <!-- load body-parser plugin --> <script src='page.js-body-parser.js'></script> <!-- sample app code --> <script> // define routes page('/testlink', function(req) { console.log(req.body); }); page('/bodytest', function(req) { console.log(req.body); }); // activate router page(); // activate body-parser plugin pageBodyParser(); </script> </body> </html>