Hello, I have an XHR that uploads large amounts of data to the server. This XHR dies intermittently and seemingly without pattern. Currently my code looks like this:
function makeFormData(data) {
var formdata = "";
for (var key in data) {
formdata = formdata + "&" + key + "=" + encodeURIComponent(data[key]);
}
return formdata.slice(1);
}
function xhr(url, data, onsuccess, onerror) {
var xhrequest = new XMLHttpRequest();
xhrequest.onreadystatechange = function () {
if (xhrequest.readyState != 4)
return;
if (xhrequest.responseText)
onsuccess(xhrequest.responseText);
}
xhrequest.onerror = function (error_param) {
onerror(error_param);
}
xhrequest.open('POST', url, true);
xhrequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhrequest.send(makeFormData(data));
}
This is in a Chrome extension. What am I doing wrong? How can I make the form multipart instead, to make the upload smaller? I have used Wireshark to trace the request and the it cuts off mid-send with many packet retransmissions (and never completes).
Please help me, this is driving me crazy.