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

199
Views
How to convert jquery post API to ES6 fetch?

So I want to refactor my code from jquery to just javascript ES6, I think it will be cleaner if it implemented that way. But I'm not sure how to implement it Here is the jquery code :

$.post({
        url: /* my url */
        data: { /* my data*/ }

        beforeSend: () => {
            //do something
        },

        success: (res) => {
            //do something            
        },

        error: (err) => {
            console.error(err)
        },

        complete: () => {
            //do something
        }
    })

How to refactor to ES6 fetch to look something like this :

fetch(url, {
        method: 'POST',
        body: /* my data */
    })
     // beforeSend code
    .then((res) => res.json())
    .then((data) => {
        //do something
    })
    // complete code
    .catch((err) => console.log(err));

I will be very grateful if you can write the code with async await, but .then() .catch() is appreciated regardless. Thanks in advance

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!