mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
Use asynchronous programming to read data files
This commit is contained in:
parent
3762339745
commit
0481f8305c
12
index.html
12
index.html
@ -4,13 +4,15 @@
|
|||||||
<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>
|
||||||
window.onload=function() {
|
window.onload=function() {
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user