generated from moevm/nsql-clean-tempate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
371b28d
commit 4f4f85a
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
let importButton = document.getElementById('import'); | ||
|
||
importButton.addEventListener('click', importData); | ||
|
||
async function importData(event) { | ||
let fileInput = document.createElement('input'); | ||
fileInput.type = 'file'; | ||
fileInput.accept = '.json'; | ||
|
||
fileInput.onchange = event => { | ||
const file = event.target.files[0]; | ||
if (file) { | ||
const reader = new FileReader(); | ||
|
||
reader.onload = function(e) { | ||
try { | ||
const jsonData = JSON.parse(e.target.result); | ||
sendJsonData(jsonData); | ||
} catch (error) { | ||
alert("Ошибка при чтении файла JSON: " + error.message); | ||
} | ||
}; | ||
reader.readAsText(file); | ||
} | ||
} | ||
fileInput.click() | ||
} | ||
|
||
async function sendJsonData(jsonData) { | ||
await fetch(new URL('/import_db', 'http://localhost:8000').href, { | ||
method: "POST", | ||
headers: { | ||
'Accept': 'application/json', | ||
"Content-type": "application/json; charset=UTF-8" | ||
}, | ||
body: JSON.stringify(jsonData) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters