In the snippet you've posted, there is nothing out of the ordinary going on - there's no reason why you must keep this in-place instead of moving to jQuery, having said that, the reason your code is hanging is because you are waiting for
readyState
to be 4 and
status
to be 200 (success) - if your server is throwing an error because the post size is too big you probably wont get a 200 status code, more likely 500
Instead of converting it to jQuery, you could just add some more checks in place
dataAccess.submitJsonWithFileRequest = function(targetUrl, fileToUpload, onComplete) {
var formData = new FormData();
formData.append(fileToUpload.name, fileToUpload);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if(xhr.status == 200)
{
var jsonData = jQuery.parseJSON(xhr.responseText);
onComplete(jsonData);
} else {
}
}
};
xhr.open('POST', targetUrl, true);
xhr.send(formData);
};