10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +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,13 +4,15 @@
<script src="scripts/data.js" type="text/javascript"></script>
<script>
function update_file(filename) {
lnk_doi=document.getElementById('lnk_doi');
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=document.getElementById('lnk_file');
getDataFromFile(file,onApplyData)
}
function onApplyData(data) {
lnk_doi=document.getElementById('lnk_doi');
lnk_doi.setAttribute('href',getDoiUrl(data));
}
</script>
<script>
window.onload=function() {

View File

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