Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

301
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda