* @function LevelRenderer.Tool.Http.prototype.get * @description get请求。 * @param {(string|IHTTPGetOption)} url - 请求url * @param {function} onsuccess - 请求成功函数 * @param {function} onerror - 请求失败函数 * @param {Object} opts - 额外参数 * @returns {number} cos值
(url, onsuccess, onerror)
| 22 | * @returns {number} cos值 |
| 23 | */ |
| 24 | get(url, onsuccess, onerror) { |
| 25 | if (typeof(url) === 'object') { |
| 26 | var obj = url; |
| 27 | url = obj.url; |
| 28 | onsuccess = obj.onsuccess; |
| 29 | onerror = obj.onerror; |
| 30 | |
| 31 | } |
| 32 | var xhr = window.XMLHttpRequest |
| 33 | ? new XMLHttpRequest() |
| 34 | : new window.ActiveXObject('Microsoft.XMLHTTP'); |
| 35 | xhr.open('GET', url, true); |
| 36 | xhr.onreadystatechange = function () { |
| 37 | if (xhr.readyState == 4) { |
| 38 | if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) { |
| 39 | onsuccess && onsuccess(xhr.responseText); |
| 40 | } else { |
| 41 | onerror && onerror(); |
| 42 | } |
| 43 | xhr.onreadystatechange = new Function(); |
| 44 | xhr = null; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | xhr.send(null); |
| 49 | } |
| 50 | |
| 51 | } |
no outgoing calls
no test coverage detected