Skip to content

Commit

Permalink
feat: add load sync api
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad-haji committed Aug 15, 2018
1 parent 80bfc78 commit 007ff2d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/app/@core/utils/load-sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Created by Mohammad.hajiaghazadeh on 8/15/2018
*/

export function loadTextFileAjaxSync(filePath, mimeType) {
const xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", filePath, false);
if (mimeType != null) {
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType(mimeType);
}
}
xmlhttp.send();
if (xmlhttp.status == 200) {
return xmlhttp.responseText;
}
else {
return null;
}
}

export function loadJSON(filePath) {
const json = loadTextFileAjaxSync(filePath, "application/json");
return JSON.parse(json);
}

0 comments on commit 007ff2d

Please sign in to comment.