diff options
| author | Daniel Jones <daniel@danieljon.es> | 2024-10-09 19:01:25 +1100 | 
|---|---|---|
| committer | Daniel Jones <daniel@danieljon.es> | 2024-10-09 19:01:25 +1100 | 
| commit | b43b035bf5b38bedac7819b80544ef7138e56ee0 (patch) | |
| tree | 21e0cfb7b5d4f8ab7c683f31c13a5f5f1da3c4cc /html | |
| parent | 513835bc354664bfaed5417e4911a74b05dd25d7 (diff) | |
html changes
create function to send post requests, use it for reset and toggling.
Diffstat (limited to 'html')
| -rwxr-xr-x | html/index.html | 34 | 
1 files changed, 29 insertions, 5 deletions
| diff --git a/html/index.html b/html/index.html index 51dedeb..20e7387 100755 --- a/html/index.html +++ b/html/index.html @@ -201,14 +201,12 @@  -->            </tr>          </tbody> -      </table> -      <iframe name="hidden_iframe" style="display:none;"></iframe> -      <form action="/reset" method="post" target="hidden_iframe"> -        <button type="submit">Restart Sign</button> -      </form> +      </table>             <form id="saveform">          <fieldset>            <legend>Customisation:</legend> +          <button type="button" id="toggledisplay" onclick="sendPostRequest('matrix', 'toggle')">Toggle Display</button>  +          <button type="button" id="restart" onclick="sendPostRequest('restart', '')">Restart Sign</button><br>            Wireless (required for time sync):<br>            <input type="text" id="cssid" name="cssid" placeholder="ssid">   <input type="password" id="cpassword"              name="cpassword" placeholder="password"> @@ -418,6 +416,32 @@      document.getElementById("datep").valueAsDate = new Date(); +    function sendPostRequest(key, value) { +    const data = { +        [key]: value +    }; + +    fetch('/cmd', { +        method: 'POST', +        headers: { +            'Content-Type': 'application/json' +        }, +        body: JSON.stringify(data) +    }) +    .then(response => { +        if (!response.ok) { +            throw new Error('Network response was not ok'); +        } +        return response.json(); +    }) +    .then(data => { +        console.log('Success:', data); +    }) +    .catch((error) => { +        console.error('Error:', error); +    }); +} +    </script>  </body> | 
