Removed deprecated XMLHttpRequest

This commit is contained in:
2017-12-01 15:38:44 +01:00
parent 4856d789a5
commit 63bd2a96fa
2 changed files with 28 additions and 24 deletions

View File

@ -13,7 +13,6 @@ export class Application {
loading: HTMLElement
currentPath: string
originalPath: string
lastRequest: XMLHttpRequest | null
constructor() {
this.currentPath = window.location.pathname
@ -35,28 +34,9 @@ export class Application {
}
get(url: string): Promise<string> {
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
})
return fetch(url, {
credentials: "same-origin"
}).then(response => response.text())
}
load(url: string, options?: LoadOptions) {
@ -87,6 +67,11 @@ export class Application {
return
}
// Outdated response.
if(this.currentPath !== url) {
return
}
// Remove listener after we finally got the correct event.
this.content.removeEventListener("transitionend", onTransitionEnd)