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

174
Views
Speed test xmlhttprequest

Good afternoon. Please tell me how can I return the 'event. loaded' which then dispatch it to the state

const startSpeedTestAsync = () => async (dispatch: Dispatch) => {
  const url = config.SPEED_TEST;


dispatch(setLoadTest(true));

const startTime = new Date().getTime();


dispatch(startSpeedTest({ startTime, isShowInfo: false }));



 const endRequest = (data: unknown) => {
    const endTime = new Date().getTime();
    dispatch(setEndTime(endTime));
    dispatch(calcSpeed(data));
    dispatch(stopSpeedTest({ isLoadTest: false, isShowInfo: true }));
  };



const sendHttpRequest = (metod: string, currenUrl: string) => {
    const promise: Promise<unknown> = new Promise((resolve) => {
      const xhr = new XMLHttpRequest();

  xhr.timeout = 5000;

  xhr.onprogress = function (event) {
    console.log('loaded: ', event.loaded);
    return event.loaded;
  };
  xhr.onreadystatechange = function () {
    // Only run if the request is complete
    if (xhr.readyState !== 4) return;
    resolve(xhr.onprogress);

    // resolve(xhr.onprogress);
  };
  xhr.open(metod, currenUrl);
  xhr.send();
});
return promise;

};

  sendHttpRequest('GET', url)
    .then((response: any) => console.log(response))
    .catch(endRequest);
};

I can not understand how to properly process the request that everything turned out. I'm trying to implement a request for xmlhttprequest and return the size of the downloaded file to then calculate the speed of the Internet connection. The problem is that I don't know how to return this size.

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!