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

303
Visualizações
Vanilla Javascript, Crop Canvas, Image uploader Via AJAX not working

I had this script working, and now it is failing.

var canvas = document.getElementById('CropCanvas');
var CroppedIMG = canvas.toDataURL('image/jpeg', 1.0);
var formData = new FormData();
var xhr = new XMLHttpRequest();
    
formData.append('AJAX_Request', 'ImgUpload');
formData.append('UploadImages', true);
formData.append('ConvertStream', 'image/jpeg');
formData.append('IMGLocation', 'Video');
formData.append('ID', ID);
formData.append('ImagesDir', Folder);
formData.append('ImagesSubDir', SubFolder);

const Image = new File([CroppedIMG], ImageName);

formData.append('Images[]', Image, ImageName);

xhr.open("POST", "AJAX.portal.php", false);

xhr.onreadystatechange = function() {

    if (xhr.status == 200) {

    }

}
xhr.send(formData);

In the console on Firefox it shows an empty payload.

If I comment out the line appending the image to the formData, it will send the payload to the server, cannot figure out why it is not working, as it was working before.

I have tried using the following headers as well (not at the same time):

xhr.setRequestHeader("Content-Type", "application/upload");
xhr.setRequestHeader("Content-Type", "multipart-form/data");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

None of which worked.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I did find the problem, the image I was testing with was larger than 2MB, as soon as I rectified this, the script started working again.

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