mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Support responseType property on XMLHttpRequest.
Only default, "" and "text" supported for now. Raising an error otherwise.
This commit is contained in:
@ -616,3 +616,16 @@ export function test_raises_onerror_Event(done) {
|
|||||||
xhr.open("GET", "https://no-such-domain-httpbin.org");
|
xhr.open("GET", "https://no-such-domain-httpbin.org");
|
||||||
xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function test_responseType(done) {
|
||||||
|
let xhr = new XMLHttpRequest();
|
||||||
|
xhr.responseType = "";
|
||||||
|
xhr.responseType = "text";
|
||||||
|
|
||||||
|
TKUnit.assertThrows(
|
||||||
|
() => xhr.responseType = "json",
|
||||||
|
"Didn't raise on unsupported type.",
|
||||||
|
"Response type of 'json' not supported."
|
||||||
|
);
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
1
declarations.d.ts
vendored
1
declarations.d.ts
vendored
@ -37,6 +37,7 @@ declare class XMLHttpRequest {
|
|||||||
overrideMimeType(mime: string): void;
|
overrideMimeType(mime: string): void;
|
||||||
readyState: number;
|
readyState: number;
|
||||||
responseText: string;
|
responseText: string;
|
||||||
|
responseType: string;
|
||||||
status: number;
|
status: number;
|
||||||
|
|
||||||
onload: () => void;
|
onload: () => void;
|
||||||
|
13
http/http.ts
13
http/http.ts
@ -49,6 +49,7 @@ export class XMLHttpRequest {
|
|||||||
private _responseText: string = "";
|
private _responseText: string = "";
|
||||||
private _headers: any;
|
private _headers: any;
|
||||||
private _errorFlag: boolean;
|
private _errorFlag: boolean;
|
||||||
|
private _responseType: string;
|
||||||
|
|
||||||
public onreadystatechange: Function;
|
public onreadystatechange: Function;
|
||||||
|
|
||||||
@ -163,6 +164,18 @@ export class XMLHttpRequest {
|
|||||||
return this._readyState;
|
return this._readyState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get responseType(): string {
|
||||||
|
return this._responseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public set responseType(value: string) {
|
||||||
|
if (value === "" || value === "text") {
|
||||||
|
this._responseType = value;
|
||||||
|
} else {
|
||||||
|
throw new Error(`Response type of '${value}' not supported.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private _setReadyState(value: number) {
|
private _setReadyState(value: number) {
|
||||||
if (this._readyState !== value) {
|
if (this._readyState !== value) {
|
||||||
this._readyState = value;
|
this._readyState = value;
|
||||||
|
Reference in New Issue
Block a user