Add gitlab issue/merge request templates
[src/app-framework-binder.git] / test / sample-post.html
1 <html>
2   <head>
3     <title>Sample Post test</title>
4   <body>
5     <h1>Sample Post test</h1>
6     
7     <h2>Sample Post File</h2>
8     <form enctype="multipart/form-data">
9         <input type="file" name="file"/>
10         <input type="hidden" name="hidden" value="bollobollo" />
11         <br>
12         <button formmethod="POST" formaction="api/post/upload-image">Post File</button>
13     </form>
14     
15     <h2>Sample Post JSON</h2>
16     
17     <form id="jsonform">
18         <input name='name' value='MyName'>
19         <input name='info' value='MyInfo'>
20         <select name='option'>
21         <option selected>opt1</option>
22         <option>opt2</option>
23         <option>opt3</option>
24         </select>
25         <label>ticked</label>
26         <input type='checkbox'  name='ticked'>
27     </form>
28     <p><input id="jsonrep" placeholder="AFB-daemon Response" readonly style="width: 100%">
29     <button onclick="xpost();">Post JSON</button>
30
31     <script>
32     // post bouton press post form as JSON
33     var xpost=function() {
34         var jform={};
35         var xform = document.querySelector('#jsonform').elements;
36         var xreqt = new XMLHttpRequest();
37         xreqt.open("POST", "api/post/upload-json", true);
38         xreqt.setRequestHeader('Content-Type', 'application/json');
39         
40         // Serialise jform in JSON
41         for(var ind = 0; ind < xform.length; ind++) {
42             console.log ("name=%s value=%s", xform[ind].name, xform[ind].value);
43             jform[xform[ind].name] = xform[ind].value;
44         }
45
46         // display afb-daemon return values
47         xreqt.onload = function () {
48             var result = "Status:" + xreqt.status + " Value:" + xreqt.responseText;
49             document.getElementById("jsonrep").value = result;
50             console.log (result);
51         };
52         
53         // Post Form as JSON
54         console.log ("Posting jform=%j", jform); 
55         xreqt.send(JSON.stringify(jform)); 
56     };
57     </script>
58
59     
60     </body>
61 </html>