39 lines
1.1 KiB
HTML
39 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="pl">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Zadanie 3</title>
|
|
<link rel="stylesheet" href="css/style.css">
|
|
</head>
|
|
|
|
<body>
|
|
<h1>Upload file by fetch, no form</h1>
|
|
<input type="file" name="wyslany_plik" id="wyslany_plik">
|
|
<button id="wyslij">upload</button>
|
|
<pre id="wiadomosc">Tu beda dane z powrotem</pre>
|
|
|
|
<script>
|
|
const przycisk = document.getElementById("wyslij")
|
|
|
|
przycisk.onclick = function () {
|
|
const fd = new FormData()
|
|
|
|
fd.append("wyslany_plik", document.getElementById("wyslany_plik").files[0])
|
|
|
|
const body = fd
|
|
|
|
fetch("/process_upload", { method: "post", body })
|
|
.then(response => response.json())
|
|
.then(function (data) {
|
|
const pre = document.getElementById("wiadomosc")
|
|
|
|
pre.innerHTML = JSON.stringify(data, null, 5)
|
|
})
|
|
.catch(err => console.error(err))
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html> |