Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!