3 <title>Sample Post test</title>
5 <h1>Sample Post test</h1>
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" />
12 <button formmethod="POST" formaction="api/post/upload-image">Post File</button>
15 <h2>Sample Post JSON</h2>
18 <input name='name' value='MyName'>
19 <input name='info' value='MyInfo'>
20 <select name='option'>
21 <option selected>opt1</option>
26 <input type='checkbox' name='ticked'>
28 <p><input id="jsonrep" placeholder="AFB-daemon Response" readonly style="width: 100%">
29 <button onclick="xpost();">Post JSON</button>
32 // post bouton press post form as JSON
33 var xpost=function() {
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');
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;
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;
54 console.log ("Posting jform=%j", jform);
55 xreqt.send(JSON.stringify(jform));