mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 13:53:48 +01:00
Add getTextFromFileAsync function
This commit is contained in:
parent
bf8449e050
commit
6a4de3f44e
@ -71,24 +71,7 @@ class data {
|
||||
this.excitations=[];
|
||||
}
|
||||
static async loadAsync(file) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET",getFullDataPath(file), true);
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status == 200) {//when a good response is given do this
|
||||
var text = req.responseText;
|
||||
resolve(data.loadString(text));
|
||||
} else {
|
||||
reject({
|
||||
status: req.status,
|
||||
statusText: req.statusText
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
req.send();
|
||||
});
|
||||
return data.loadString(await getTextFromFileAsync(getFullDataPath(file)));
|
||||
}
|
||||
static loadString(text) {
|
||||
// for each line with metadata
|
||||
|
20
content/scripts/getTextFromFile.js
Normal file
20
content/scripts/getTextFromFile.js
Normal file
@ -0,0 +1,20 @@
|
||||
async function getTextFromFileAsync(file) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var req = new XMLHttpRequest();
|
||||
req.open("GET",file, true);
|
||||
req.onreadystatechange = function() {
|
||||
if (req.readyState == 4) {
|
||||
if (req.status == 200) {//when a good response is given do this
|
||||
var text = req.responseText;
|
||||
resolve(text);
|
||||
} else {
|
||||
reject({
|
||||
status: req.status,
|
||||
statusText: req.statusText
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
req.send();
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user