function sendForm() { var fileData = new FormData(document.getElementById("cpd-file")); var xhr = new XMLHttpRequest(); xhr.open("POST", "/upload_file", true); xhr.setRequestHeader('Accept', 'application/json'); xhr.onload = function(progressEvent) { if (xhr.status == 200) { console.log('Uploaded', xhr); } else { console.log("Error " + xhr.status + " occurred uploading your file.", xhr); } }; xhr.send(oData); }