Update version 0.2.1: Fix issue #18

Fix `UNAUTHORIZED` error message popping up when browsing
This commit is contained in:
Joxit 2017-06-11 23:04:15 +02:00
parent 2d9b3886de
commit 36cbda1263
8 changed files with 230 additions and 111 deletions

View file

@ -29,14 +29,14 @@ Http.prototype.addEventListener = function(e, f) {
self.oReq.addEventListener('loadend', function() {
if (this.status == 401) {
var req = new XMLHttpRequest();
for (key in this.http._events) {
req.addEventListener(key, this.http._events[key]);
for (key in self._events) {
req.addEventListener(key, self._events[key]);
}
for (key in this.http._headers) {
req.setRequestHeader(key, this.http._headers[key]);
for (key in self._headers) {
req.setRequestHeader(key, self._headers[key]);
}
req.withCredentials = true;
req.open(this.http._method, this.http._url);
req.open(self._method, self._url);
req.send();
} else {
f.bind(this)();
@ -44,6 +44,15 @@ Http.prototype.addEventListener = function(e, f) {
});
break;
}
case 'load':
{
self.oReq.addEventListener('load', function() {
if (this.status !== 401) {
f.bind(this)();
}
});
break;
}
default:
{
self.oReq.addEventListener(e, function() {
@ -66,6 +75,5 @@ Http.prototype.open = function(m, u) {
};
Http.prototype.send = function() {
this.oReq.http = this;
this.oReq.send();
};