I have an XHR that uploads large amounts of data to a server. This XHR dies intermittently and, it would seem, without a pattern. Currently my code is as follows:
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 a Chrome extension. What am I doing wrong? How can I make multipart form to make loading less? I used Wireshark to track the request, and it disables the average sending with multiple packet retransmissions (and never completes).
Please help me, it drives me crazy.
source share