2023-12-27 23:55:31 +07:00
|
|
|
function sendHttpRequest(url, method, data, callback, contentType = "multipart/form-data") {
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open(method, url, true);
|
|
|
|
xhr.setRequestHeader("Content-Type", contentType);
|
|
|
|
xhr.onreadystatechange = function () {
|
|
|
|
if (xhr.readyState === 4) {
|
|
|
|
if (xhr.status === 200) {
|
2024-02-11 13:20:10 +07:00
|
|
|
var response = xhr.responseText;
|
2023-12-27 23:55:31 +07:00
|
|
|
callback(null, response);
|
|
|
|
}
|
2024-02-11 13:20:10 +07:00
|
|
|
else callback(xhr.status, null);
|
2023-12-27 23:55:31 +07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
var requestData;
|
2024-02-11 13:20:10 +07:00
|
|
|
if (contentType === "application/json") requestData = JSON.stringify(data);
|
|
|
|
else requestData = data;
|
2023-12-27 23:55:31 +07:00
|
|
|
xhr.send(requestData);
|
|
|
|
}
|