28 lines
566 B
JavaScript
28 lines
566 B
JavaScript
|
export default class FileLoader
|
||
|
{
|
||
|
constructor(filename)
|
||
|
{
|
||
|
this.filename = filename;
|
||
|
this.content = '';
|
||
|
this.loadContent();
|
||
|
}
|
||
|
|
||
|
getContent()
|
||
|
{
|
||
|
return this.content;
|
||
|
}
|
||
|
|
||
|
loadContent()
|
||
|
{
|
||
|
let request = new XMLHttpRequest();
|
||
|
|
||
|
request.onreadystatechange = () => {
|
||
|
if (request.status === 200 && request.readyState === 4) {
|
||
|
this.content = request.responseText;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
request.open('GET', this.filename, false);
|
||
|
request.send();
|
||
|
}
|
||
|
}
|