-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
29 lines (26 loc) · 793 Bytes
/
script.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
function importCSV() {
var form = document.getElementById('csvForm');
var resultDiv = document.getElementById('result');
var formData = new FormData(form);
fetch('import.php', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log(data); // Log the response to the console
if (data.count !== undefined) {
resultDiv.innerHTML = 'Records imported: ' + data.count;
} else {
resultDiv.innerHTML = 'Invalid response from server.';
}
})
.catch(error => {
resultDiv.innerHTML = 'Error: ' + error.message;
});
}