diff --git a/carrack.js b/carrack.js index 6ad1f2d..7752eea 100644 --- a/carrack.js +++ b/carrack.js @@ -1,33 +1,18 @@ 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) { - // Successful response - var response; - if (contentType === "application/json") { - response = JSON.parse(xhr.responseText); - } else { - response = xhr.responseText; - } + var response = xhr.responseText; callback(null, response); - } else { - // Error response - callback(xhr.status, null); } + else callback(xhr.status, null); } }; - var requestData; - if (contentType === "application/json") { - requestData = JSON.stringify(data); - } else { - requestData = data; - } - + if (contentType === "application/json") requestData = JSON.stringify(data); + else requestData = data; xhr.send(requestData); }