summaryrefslogtreecommitdiffstats
path: root/test/sample-post.html
blob: b1486c3b0b26d2ee8ce838bc14549ea12f03420a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type 
<html>
  <head>
    <title>Sample Post test</title>
  <body>
    <h1>Sample Post test</h1>
    
    <h2>Sample Post File</h2>
    <form enctype="multipart/form-data">
        <input type="file" name="select input file" />
        <input type="hidden" name="hidden" value="bollobollo" />
        <br>
        <button formmethod="POST" formaction="api/post/upload-image">Post File</button>
    </form>
    
    <h2>Sample Post JSON</h2>
    
    <form id="jsonform">
        <input name='name' value='MyName'>
        <input name='info' value='MyInfo'>
        <select name='option'>
        <option selected>opt1</option>
        <option>opt2</option>
        <option>opt3</option>
        </select>
        <label>ticked</label>
        <input type='checkbox'  name='ticked'>
    </form>
    <p><input id="jsonrep" placeholder="AFB-daemon Response" readonly style="width: 100%">
    <button onclick="xpost();">Post JSON</button>

    <script>
    // post bouton press post form as JSON
    var xpost=function() {
        var jform={};
        var xform = document.querySelector('#jsonform').elements;
        var xreqt = new XMLHttpRequest();
        xreqt.open("POST", "api/post/upload-json", true);
        xreqt.setRequestHeader('Content-Type', 'application/json');
        
        // Serialise jform in JSON
        for(var ind = 0; ind < xform.length; ind++) {
            console.log ("name=%s value=%s", xform[ind].name, xform[ind].value);
            jform[xform[ind].name] = xform[ind].value;
        }

        // display afb-daemon return values
        xreqt.onload = function () {
            var result = "Status:" + xreqt.status + " Value:" + xreqt.responseText;
            document.getElementById("jsonrep").value = result;
            console.log (result);
        };
        
        // Post Form as JSON
        console.log ("Posting jform=%j", jform); 
        xreqt.send(JSON.stringify(jform)); 
    };
    </script>

    
    </body>
</html>