correct html

This commit is contained in:
Anatoly Prohacky 2023-04-23 19:08:08 +10:00
parent cd6f6a924b
commit f0f5be40e9

View File

@ -13,7 +13,7 @@
<!-- Адаптив -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<script src="https://snipp.ru/cdn/jquery/2.1.1/jquery.min.js"></script>
<script src="js/button"></script>
<script src="js/button.js"></script>
</head>
<body>
@ -40,26 +40,31 @@
</body>
<script>
$('.input-file input[type=file]').on('change', function(){
$('.input-file input[type=file]').on('change', function(){
let file = this.files[0];
$(this).closest('.input-file').find('.input-file-text').html(file.name);
});
});
function uploadFile() {
function uploadFile() {
let fileInput = document.getElementById("myFile");
file = fileInput.files[0]
let formData = new FormData();
formData.append("file", file);
let fileDown = file.name.replace(/\.[^.]+$/, "")
let fileRes = file.name.split('').reverse().join('').split('.')[0].split('').reverse().join('');
if (fileRes != "json") {
alert(`Format file not json`);
return
}
fetch("https://sirius.gitstore.ru/api/sirius", {
method: "POST",
body: formData
})
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP ${response.status} - ${response.statusText}`);
throw new Error(`HTTP ${response.status} - ${response.body}`);
}
return response.blob();
})
@ -74,10 +79,11 @@
a.click();
a.parentNode.removeChild(a);
setTimeout(() => { URL.revokeObjectURL(downloadUrl) }, 1000);
})
.catch((err) => {
throw err;
});
})
.catch((err) => {
alert(err);
return
});
}
</script>
</html>