|
|
Ok!
|
|
|
Ok!
|
|---|---|---|---|---|
| 201 | function send(onError, onSuccess, url, method = 'GET', data = null, headers = [], timeout = 60000) {
let xhr;
if (window.XMLHttpRequest) {
// Chrome, Mozilla, Opera, Safari
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// Internet Explorer
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open(method, url, true);
headers.forEach((header) => {
xhr.setRequestHeader(header.key, header.value);
})
xhr.timeout = timeout;
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if(xhr.status >= 400) {
onError(xhr.statusText)
} else {
onSuccess(xhr.responseText)
}
}
}
xhr.send(data);
} | xhr, request, XMLHttpRequest, JS | 12090 | XMLHttpRequest обернутый в функцию |