forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttp.js
More file actions
59 lines (53 loc) · 1.38 KB
/
Http.js
File metadata and controls
59 lines (53 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @private
* @class SuperMap.LevelRenderer.Tool.Http
* LevelRenderer 工具-Http
*
*/
export class Http {
/**
* Constructor: SuperMap.LevelRenderer.Tool.Http
* 构造函数。
*
*/
constructor() {
this.CLASS_NAME = "SuperMap.LevelRenderer.Tool.Http"
}
/**
* Method: get
* get请求。
*
* Parameters:
* url - {string|IHTTPGetOption}
* onsuccess - {Function}
* onerror - {Function}
* opts - {Object} 额外参数
*
* Returns:
* {Number} cos 值。
*/
get(url, onsuccess, onerror) {
if (typeof(url) === 'object') {
var obj = url;
url = obj.url;
onsuccess = obj.onsuccess;
onerror = obj.onerror;
}
var xhr = window.XMLHttpRequest
? new XMLHttpRequest()
: new window.ActiveXObject('Microsoft.XMLHTTP');
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
onsuccess && onsuccess(xhr.responseText);
} else {
onerror && onerror();
}
xhr.onreadystatechange = new Function();
xhr = null;
}
};
xhr.send(null);
}
}