-
Book Overview & Buying
-
Table Of Contents
HTML5 Data and Services Cookbook
One of the new features added to XMLHttpRequest Level 2 (http://www.w3.org/TR/XMLHttpRequest2/) is the FormData object. This enables us to use a set of key-value pairs that can be sent using AJAX. The most common use is in sending binary files or any other large amount of data. In this recipe, we will create two scripts that will send FormData, one with a plain JavaScript and the other with jQuery, as well as the server-side code to support it.
The server will be done in Nodejs using restify (http://mcavage.github.io/node-restify/). In order to install the dependencies, a package.json file can be created where restify will be added.
The server should be able to accept HTTP POST with type multipart/form-data; that is why there is a built-in plugin for restify called BodyParser. This will block the parsing of the HTTP request body:
var server = restify.createServer();
server.use(restify.bodyParser({ mapParams: false }));
server.post('hi...
Change the font size
Change margin width
Change background colour