Created
October 18, 2015 12:36
-
-
Save mnsmarcelo/8314d8661621570fe017 to your computer and use it in GitHub Desktop.
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
document.getElementsByClassName("btn")[0].addEventListener("click", function () { | |
var arquivos = document.getElementsByClassName("arquivos")[0].files; | |
var dados = new FormData(); | |
var url = new XMLHttpRequest(); | |
for (var i = 0; i < arquivos.length; i++) { | |
dados.append("arquivo[]", arquivos[i]); | |
} | |
url.open("POST", "/upload.php"); | |
url.send(dados); | |
url.onreadystatechange = function () { | |
if (url.readyState == 4) { | |
if (url.status == 200) { | |
document.getElementsByClassName("alert-success")[0].innerHTML = '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span> Enviado com sucesso'; | |
document.getElementsByClassName("alert-success")[0].style.display = "block"; | |
} | |
if (url.status == 404) { | |
document.getElementsByClassName("alert-danger")[0].innerHTML = '<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span><span class="sr-only">Error:</span> Ooops houve um erro: 404'; | |
document.getElementsByClassName("alert-danger")[0].style.display = "block"; | |
} | |
} | |
document.getElementsByClassName("miniaturas")[0].innerHTML = ""; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment