1var formData = new FormData();
2
3formData.append("username", "Groucho");
4formData.append("accountnum", 123456); // number 123456 is immediately converted to a string "123456"
5
6// HTML file input, chosen by user
7formData.append("userfile", fileInputElement.files[0]);
8
9// JavaScript file-like object
10var content = '<a id="a"><b id="b">hey!</b></a>'; // the body of the new file...
11var blob = new Blob([content], { type: "text/xml"});
12
13formData.append("webmasterfile", blob);
14
15var request = new XMLHttpRequest();
16request.open("POST", "http://foo.com/submitform.php");
17request.send(formData);
18