Skip to content

Instantly share code, notes, and snippets.

@talcual
Created July 24, 2019 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talcual/d97913f82ae81e6c0416bcea59c44b7b to your computer and use it in GitHub Desktop.
Save talcual/d97913f82ae81e6c0416bcea59c44b7b to your computer and use it in GitHub Desktop.
function upfiles(model, method, args, filement, backcall){
var doc = eval(document.getElementById(filement));
console.log(doc);
var docx = doc.files;
var formData = new FormData();
var ins = doc.files.length;
for (var x = 0; x < ins; x++) {
formData.append("element[]", docx[x]);
}
formData.append('model', model);
formData.append('method', method);
formData.append('args', args);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener('progress', onprogressHandler, false);
xhr.open('POST', 'app.php', true);
xhr.onreadystatechange = function () {
if(xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
let r = JSON.parse(xhr.responseText);
if(typeof backcall == 'function'){
backcall(r);
}
}
};
xhr.send(formData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment