mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Support onload/onerror events on XMLHttpRequest.
This commit is contained in:
19
http/http.ts
19
http/http.ts
@ -39,6 +39,9 @@ export class XMLHttpRequest {
|
||||
public LOADING = 3;
|
||||
public DONE = 4;
|
||||
|
||||
public onload: () => void;
|
||||
public onerror: () => void;
|
||||
|
||||
private _options: definition.HttpRequestOptions;
|
||||
private _readyState: number;
|
||||
private _status: number;
|
||||
@ -112,8 +115,9 @@ export class XMLHttpRequest {
|
||||
}
|
||||
|
||||
}).catch(e => {
|
||||
this._errorFlag = true;
|
||||
});
|
||||
this._errorFlag = true;
|
||||
this._setReadyState(this.DONE);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,6 +171,15 @@ export class XMLHttpRequest {
|
||||
this.onreadystatechange();
|
||||
}
|
||||
}
|
||||
|
||||
if (this._readyState === this.DONE) {
|
||||
if (this._errorFlag && types.isFunction(this.onerror)) {
|
||||
this.onerror();
|
||||
}
|
||||
if (!this._errorFlag && types.isFunction(this.onload)) {
|
||||
this.onload();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get responseText(): string {
|
||||
@ -230,4 +243,4 @@ var statuses = {
|
||||
503: "Service Unavailable",
|
||||
504: "Gateway Timeout",
|
||||
505: "HTTP Version Not Supported"
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user