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

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

mercurial