browser/devtools/netmonitor/test/html_post-data-test-page.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!-- Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ -->
michael@0 3 <!doctype html>
michael@0 4
michael@0 5 <html>
michael@0 6 <head>
michael@0 7 <meta charset="utf-8"/>
michael@0 8 <title>Network Monitor test page</title>
michael@0 9 <style>
michael@0 10 input {
michael@0 11 display: block;
michael@0 12 margin: 12px;
michael@0 13 }
michael@0 14 </style>
michael@0 15 </head>
michael@0 16
michael@0 17 <body>
michael@0 18 <p>POST data test</p>
michael@0 19 <form enctype="multipart/form-data" method="post" name="form-name">
michael@0 20 <input type="text" name="text" placeholder="text" value="Some text..."/>
michael@0 21 <input type="email" name="email" placeholder="email"/>
michael@0 22 <input type="range" name="range" value="42"/>
michael@0 23 <input type="button" value="Post me!" onclick="window.form()">
michael@0 24 </form>
michael@0 25
michael@0 26 <script type="text/javascript">
michael@0 27 function post(aAddress, aMessage, aCallback) {
michael@0 28 var xhr = new XMLHttpRequest();
michael@0 29 xhr.open("POST", aAddress, true);
michael@0 30 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
michael@0 31
michael@0 32 var data = "";
michael@0 33 for (var i in aMessage) {
michael@0 34 data += "&" + i + "=" + aMessage[i];
michael@0 35 }
michael@0 36
michael@0 37 xhr.onreadystatechange = function() {
michael@0 38 if (this.readyState == this.DONE) {
michael@0 39 aCallback();
michael@0 40 }
michael@0 41 };
michael@0 42 xhr.send(data);
michael@0 43 }
michael@0 44
michael@0 45 function form(aAddress, aForm, aCallback) {
michael@0 46 var formData = new FormData(document.forms.namedItem(aForm));
michael@0 47 formData.append("Custom field", "Extra data");
michael@0 48
michael@0 49 var xhr = new XMLHttpRequest();
michael@0 50 xhr.open("POST", aAddress, true);
michael@0 51
michael@0 52 xhr.onreadystatechange = function() {
michael@0 53 if (this.readyState == this.DONE) {
michael@0 54 aCallback();
michael@0 55 }
michael@0 56 };
michael@0 57 xhr.send(formData);
michael@0 58 }
michael@0 59
michael@0 60 function performRequests() {
michael@0 61 var url = "sjs_simple-test-server.sjs";
michael@0 62 var url1 = url + "?foo=bar&baz=42&type=urlencoded";
michael@0 63 var url2 = url + "?foo=bar&baz=42&type=multipart";
michael@0 64
michael@0 65 post(url1, { foo: "bar", baz: 123 }, function() {
michael@0 66 form(url2, "form-name", function() {
michael@0 67 // Done.
michael@0 68 });
michael@0 69 });
michael@0 70 }
michael@0 71 </script>
michael@0 72 </body>
michael@0 73
michael@0 74 </html>

mercurial