12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <button onclick="uploadCert();">Upload</button>
- <script>
- function uploadCert() {
- // create file input element
- const input = document.createElement('input');
- input.type = 'file';
-
- // add change listener to file input
- input.addEventListener('change', () => {
- // create form data object
- const formData = new FormData();
-
- // add selected file to form data
- formData.append('file', input.files[0]);
- // send form data to server
- fetch('/cert/upload', {
- method: 'POST',
- body: formData
- })
- .then(response => {
- if (response.ok) {
- alert('File upload successful!');
- } else {
- response.text().then(text => {
- alert(text);
- });
- //console.log(response.text());
- //alert('File upload failed!');
- }
- })
- .catch(error => {
- alert('An error occurred while uploading the file.');
- console.error(error);
- });
- });
-
- // click file input to open file selector
- input.click();
- }
- </script>
|