mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
null ref fixed
This commit is contained in:
@@ -110,6 +110,17 @@ export var test_XMLHttpRequest_headersSentAndReceivedProperly = function (done)
|
|||||||
// </snippet>
|
// </snippet>
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export var test_XMLHttpRequest_setResponseTypeShouldNotThrow = function (done) {
|
||||||
|
try {
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
(<any>xhr)._setResponseType();
|
||||||
|
done(null);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
done(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export var test_XMLHttpRequest_contentSentAndReceivedProperly = function (done) {
|
export var test_XMLHttpRequest_contentSentAndReceivedProperly = function (done) {
|
||||||
// <snippet module="xhr" title="xhr">
|
// <snippet module="xhr" title="xhr">
|
||||||
// ### Send/receive JSON
|
// ### Send/receive JSON
|
||||||
|
|||||||
11
xhr/xhr.ts
11
xhr/xhr.ts
@@ -116,13 +116,18 @@ export class XMLHttpRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setResponseType() {
|
private _setResponseType() {
|
||||||
const contentType = this.getResponseHeader('Content-Type').toLowerCase();
|
const header = this.getResponseHeader('Content-Type');
|
||||||
|
const contentType = header && header.toLowerCase();
|
||||||
|
|
||||||
|
if (contentType) {
|
||||||
if (contentType.indexOf('application/json') >= 0) {
|
if (contentType.indexOf('application/json') >= 0) {
|
||||||
this.responseType = XMLHttpRequestResponseType.json;
|
this.responseType = XMLHttpRequestResponseType.json;
|
||||||
} else if (contentType.indexOf('text/plain') >= 0) {
|
} else if (contentType.indexOf('text/plain') >= 0) {
|
||||||
this.responseType = XMLHttpRequestResponseType.text;
|
this.responseType = XMLHttpRequestResponseType.text;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.responseType = XMLHttpRequestResponseType.text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _listeners: Map<string, Array<Function>> = new Map<string, Array<Function>>();
|
private _listeners: Map<string, Array<Function>> = new Map<string, Array<Function>>();
|
||||||
@@ -309,8 +314,8 @@ export class FormData {
|
|||||||
toString(): string {
|
toString(): string {
|
||||||
var arr = new Array<string>();
|
var arr = new Array<string>();
|
||||||
|
|
||||||
this._data.forEach(function (value, name, map) {
|
this._data.forEach(function(value, name, map) {
|
||||||
arr.push(`${encodeURIComponent(name) }=${encodeURIComponent(value) }`);
|
arr.push(`${encodeURIComponent(name)}=${encodeURIComponent(value)}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
return arr.join("&");
|
return arr.join("&");
|
||||||
|
|||||||
Reference in New Issue
Block a user