-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
43 lines (37 loc) · 1.23 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function previewFile(){
var preview = document.querySelector("#img-upload"); //selects the query named img
var nonBtn = document.querySelector(".anon-btn");
var file = document.querySelector('input[type=file]').files[0]; //sames as here
var reader = new FileReader();
reader.onloadend = function () {
preview.src = reader.result;
nonBtn.classList.toggle("anon-btn")
}
if (file) {
reader.readAsDataURL(file); //reads the data as a URL
} else {
preview.src = "";
}
}
function fetchImg(){
document.querySelector("#loading").classList.toggle("hide-loading")
setTimeout(function(){
const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4){
if(xhr.status == 200){
document.querySelector("#img-upload").src = xhr.response
console.log(xhr.responseText);
}
if(xhr.status ==404){
console.log("File or resource not found!")
}
}
};
xhr.open('get', 'db.txt', true);
xhr.send();
} ,3000)
setTimeout(function() {document.querySelector("#loading").classList.toggle("hide-loading")},3000)
}
function clearAll(){
}