Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
Why the e.preventDefault is cancelling all the other lines of code after itself?

When I put the e.preventdefault() after the code it works, however it refreshes the page.

If I leave it at the beginning of the code, it prevent the other lines to run and don't pull the request.

  function loadPhoto(e){
    e.preventDefault();
    //forming images
    var formData  = new FormData( document.getElementById("uploading") );
    for(var i = 0; i < document.getElementById("up").files.length; i++) {
      console.log(i)
      formData.append("up[]",document.getElementById("up").files[i]);
    }


    var filename = document.getElementById('up');
    alert(filename)
    filename = filename.files[0].name;
    alert(filename)

    var xhr = new XMLHttpRequest();
    xhr.open('POST', '/reqUpload');
    xhr.onload = function(){
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        alert(this.responseText)
             document.getElementById('#photo').innerHTML = this.responseText;
    }
    xhr.send(formData);
  }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I resolved it by using onclick="loadPhoto(event)"

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda