10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 22:03:49 +01:00

Use asynchronous programming to read data files

This commit is contained in:
Mickaël Véril 2019-08-22 11:00:58 +02:00
parent 3762339745
commit 0481f8305c
2 changed files with 16 additions and 11 deletions

View File

@ -4,12 +4,14 @@
<script src="scripts/data.js" type="text/javascript"></script> <script src="scripts/data.js" type="text/javascript"></script>
<script> <script>
function update_file(filename) { function update_file(filename) {
lnk_doi=document.getElementById('lnk_doi');
file=filename+'.json' file=filename+'.json'
data=getDataFromFile(file)
lnk_doi.setAttribute('href',getDoiUrl(data));
lnk_file=document.getElementById('lnk_file');
lnk_file.setAttribute('href',getFullDataPath(file)); lnk_file.setAttribute('href',getFullDataPath(file));
lnk_file=document.getElementById('lnk_file');
getDataFromFile(file,onApplyData)
}
function onApplyData(data) {
lnk_doi=document.getElementById('lnk_doi');
lnk_doi.setAttribute('href',getDoiUrl(data));
} }
</script> </script>
<script> <script>

View File

@ -1,13 +1,16 @@
function getDataFromFile(file) { function getDataFromFile(file,fn) {
var result = null; var result = null;
var xmlhttp = new XMLHttpRequest(); var xmlhttp = new XMLHttpRequest();
xmlhttp xmlhttp
xmlhttp.open("GET",getFullDataPath(file), false); xmlhttp.open("GET",getFullDataPath(file), true);
xmlhttp.send(); xmlhttp.onreadystatechange = function() {
if (xmlhttp.status==200) { if (this.readyState == 4 && this.status == 200) {//when a good response is given do this
text = xmlhttp.responseText;
var data = JSON.parse(this.responseText); // convert the response to a json object
fn(data)
}
} }
return JSON.parse(text); xmlhttp.send();
} }
function getDoiUrl(data) { function getDoiUrl(data) {