1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
---|
2 | <html> |
---|
3 | <head> |
---|
4 | <title>XHR MultiPart Tests</title> |
---|
5 | <style type="text/css"> |
---|
6 | @import "../../../dojo/resources/dojo.css"; |
---|
7 | @import "../../../dijit/tests/css/dijitTests.css"; |
---|
8 | </style> |
---|
9 | |
---|
10 | <script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug:true"></script> |
---|
11 | <script type="text/javascript" src="../xhrMultiPart.js"></script> |
---|
12 | <script type="text/javascript"> |
---|
13 | var testXhrMulti, testXhrMultiForm, testXhrMultiFormWithFile; |
---|
14 | |
---|
15 | require(['dojox/io/xhrMultiPart'], function(xhrMultiPart){ |
---|
16 | var content = [ |
---|
17 | { name: "foo", content: "FOObarbaz", filename: "foo.txt" }, |
---|
18 | { name: "bar", content: "fooBARbaz", filename: "bar.txt" }, |
---|
19 | { name: "baz", content: "foobarBAZ", filename: "baz.txt" } |
---|
20 | ]; |
---|
21 | |
---|
22 | testXhrMulti = function(){ |
---|
23 | xhrMultiPart({ |
---|
24 | url: "result.txt", |
---|
25 | file: content, |
---|
26 | load: function(data){ console.log("Test with file: ", data); } |
---|
27 | }); |
---|
28 | |
---|
29 | // should be the same. |
---|
30 | xhrMultiPart({ |
---|
31 | url: "result.txt", |
---|
32 | content: content, |
---|
33 | load: function(data){ console.log("Test with content: ", data); } |
---|
34 | }); |
---|
35 | } |
---|
36 | |
---|
37 | testXhrMultiForm = function(){ |
---|
38 | xhrMultiPart({ |
---|
39 | url: "result.txt", |
---|
40 | form: dojo.byId("formTest"), |
---|
41 | load: function(data){ console.log("Test with form: ", data); } |
---|
42 | }); |
---|
43 | return false; // stop the submission |
---|
44 | } |
---|
45 | |
---|
46 | testXhrMultiFormWithFile = function(){ |
---|
47 | try { |
---|
48 | xhrMultiPart({ |
---|
49 | url: "result.txt", |
---|
50 | form: dojo.byId("formTestWithFile"), |
---|
51 | load: function(data){ console.log("Test with form: ", data); } |
---|
52 | }); |
---|
53 | } catch(e){ |
---|
54 | console.warn("xhrMultiPart failed because the form contains a FILE element!"); |
---|
55 | } |
---|
56 | return false; // stop the submission |
---|
57 | } |
---|
58 | }); |
---|
59 | </script> |
---|
60 | </head> |
---|
61 | <body class="tundra"> |
---|
62 | <h1>XHR MultiParts Tests</h1> |
---|
63 | <p>Run this test from a web server, not from local disk.</p> |
---|
64 | <p> |
---|
65 | <button onclick="testXhrMulti()">Test xhrMultiPart</button> |
---|
66 | </p> |
---|
67 | <div> |
---|
68 | <form id="formTest" onsubmit="return testXhrMultiForm()"> |
---|
69 | <input type="hidden" name="foo" value="FOObarbaz" /> |
---|
70 | <input type="hidden" name="bar" value="fooBARbaz" /> |
---|
71 | <input type="hidden" name="baz" value="foobarBAZ" /> |
---|
72 | <input type="submit" value="Test xhrMultiPart with form values" /> |
---|
73 | </form> |
---|
74 | </div> |
---|
75 | <div> |
---|
76 | <form id="formTestWithFile" onsubmit="return testXhrMultiFormWithFile()"> |
---|
77 | <input type="hidden" name="foo" value="FOObarbaz" /> |
---|
78 | <input type="hidden" name="bar" value="fooBARbaz" /> |
---|
79 | <input type="hidden" name="baz" value="foobarBAZ" /> |
---|
80 | <input type="file" name="fileTest" value="" /> |
---|
81 | <input type="submit" value="Test xhrMultiPart (prevent file upload)" /> |
---|
82 | </form> |
---|
83 | </div> |
---|
84 | </body> |
---|
85 | </html> |
---|