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

362
Views
Function on XMLHttpRequest.upload progress event not firing on Safari/Firefox (works on Chrome)

I have a form on a Prestashop's website where users can upload files. Those files can be heavy sometimes so i needed a progress bar with a percentage displaying in real time.

I did it with the <progress> tag and the XMLHttpRequest object.

Everything's working fine on Chrome but nothing happens in Safari and Firefox.

Here's the javascript code :

function uploadFile(event){
        const xhr = new XMLHttpRequest()

        xhr.open(
            'POST',
            event.currentTarget.getAttribute('action')
        )

        xhr.upload.addEventListener(
            'progress',
            fillProgressBar
        )

        xhr.send(new FormData(event.currentTarget))
    }

    const progressElement = document.body.querySelector('progress')
    const progressInformation = document.body.querySelector('#progress_information')

    function fillProgressBar({lengthComputable, loaded, total}){
        const progression = lengthComputable ? ((loaded / total) * 100).toFixed(0) : 0
        progressInformation.textContent = progression
        progressElement.value = progression
        
    }

    const customForm = document.body.querySelector('#custom_form');

    customForm.addEventListener(
        'submit',
        uploadFile
    )

When i test a console.log('Hello') in :

xhr.upload.addEventListener(
    'progress',
    console.log('Hello')
    fillProgressBar
)

I can see it in the console, the problem is the function fillProgressBarwho just never fires.

I have searched a lot on the Internet in vain...

What can I do on this one fellas ?

Thanks for reading !

about 4 years ago · Juan Pablo Isaza
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!