Reverted fetch usage

This commit is contained in:
2017-12-01 19:37:19 +01:00
parent 9c0f066053
commit e730542c63
3 changed files with 270 additions and 236 deletions

View File

@ -13,6 +13,7 @@ export class Application {
loading: HTMLElement
currentPath: string
originalPath: string
lastRequest: XMLHttpRequest | null
constructor() {
this.currentPath = window.location.pathname
@ -34,9 +35,32 @@ export class Application {
}
get(url: string): Promise<string> {
return fetch(url, {
credentials: "same-origin"
}).then(response => response.text())
// return fetch(url, {
// credentials: "same-origin"
// }).then(response => response.text())
if(this.lastRequest) {
this.lastRequest.abort()
this.lastRequest = null
}
return new Promise((resolve, reject) => {
let request = new XMLHttpRequest()
request.onerror = () => reject(new Error("You are either offline or the requested page doesn't exist."))
request.ontimeout = () => reject(new Error("The page took too much time to respond."))
request.onload = () => {
if(request.status < 200 || request.status >= 400)
reject(request.responseText)
else
resolve(request.responseText)
}
request.open("GET", url, true)
request.send()
this.lastRequest = request
})
}
load(url: string, options?: LoadOptions) {