Created
October 16, 2018 13:23
-
-
Save jastisriradheshyam/f8775401481a3d87d3f2e17ad53bd306 to your computer and use it in GitHub Desktop.
Document in upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var someFunctionToUse = function (obj) { | |
// Form data | |
var formData = new FormData(); | |
// Appending the files data in form data | |
formData.append("doc_file", document.getElementById("upload_input_id").files[0]); | |
// (Example) attribute from an object | |
formData.append("data_filed_name", obj.getAttribute("object_attribute_name")); | |
// Creating the Request object | |
var oReq = new XMLHttpRequest(); | |
// Creating event | |
oReq.onreadystatechange = function () { | |
// Checking the ready state and response | |
if (this.readyState == 4 && this.status == 200) { | |
let response = JSON.parse(this.response); | |
// Checking the resposne (Example) | |
if (response["status"] == "success") { | |
location.reload(); | |
} else { | |
console.log(response, " ", response.status) | |
} | |
} | |
}; | |
// Creating the POST request and with async | |
oReq.open("POST", "/someURL", true); | |
// Sending the request | |
oReq.send(formData); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment