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" /> <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="https://snipp.ru/cdn/jquery/2.1.1/jquery.min.js"></script>
<script src="js/button"></script> <script src="js/button.js"></script>
</head> </head>
<body> <body>
@ -40,26 +40,31 @@
</body> </body>
<script> <script>
$('.input-file input[type=file]').on('change', function(){ $('.input-file input[type=file]').on('change', function(){
let file = this.files[0]; let file = this.files[0];
$(this).closest('.input-file').find('.input-file-text').html(file.name); $(this).closest('.input-file').find('.input-file-text').html(file.name);
}); });
function uploadFile() { function uploadFile() {
let fileInput = document.getElementById("myFile"); let fileInput = document.getElementById("myFile");
file = fileInput.files[0] file = fileInput.files[0]
let formData = new FormData(); let formData = new FormData();
formData.append("file", file); formData.append("file", file);
let fileDown = file.name.replace(/\.[^.]+$/, "") 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", { fetch("https://sirius.gitstore.ru/api/sirius", {
method: "POST", method: "POST",
body: formData body: formData
}) })
.then(response => { .then(response => {
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP ${response.status} - ${response.statusText}`); throw new Error(`HTTP ${response.status} - ${response.body}`);
} }
return response.blob(); return response.blob();
}) })
@ -74,10 +79,11 @@
a.click(); a.click();
a.parentNode.removeChild(a); a.parentNode.removeChild(a);
setTimeout(() => { URL.revokeObjectURL(downloadUrl) }, 1000); setTimeout(() => { URL.revokeObjectURL(downloadUrl) }, 1000);
}) })
.catch((err) => { .catch((err) => {
throw err; alert(err);
}); return
});
} }
</script> </script>
</html> </html>