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

189
Views
How to post all form data as is via FETCH?

I have seen examples for how to POST form data via FETCH but they seem to either add form variables 1 by 1, or send the whole thing via JSON.

For reference, I use JQUERY $.post without issues, but i wanted to start using FETCH.

My current code is:

$(".btn_submit").on("click",function (){
let postvars;
        postvars = $('#myForm').serializeArray();
        //postvars.push({name: 'newvar', value: 123}); //uncomment if you need to add vars in the postvars

        let url = "engine/api.php";
        let act = "";
        $.post(`${url}?act=${act}&=`, postvars, function (data) {
            var stat = data.stat;
            var statMsg = data.statMsg;
            var myData = data.data;

            if (stat == 'ok') {
                notify(statMsg, "success");


        }).fail(function (d) {
            showAlert(d.status)
        });
 });

This works perfectly for me.

But I can't seem to find an equivalent of that via FETCH. Best i could get at is:

            let form = document.getElementById("myForm");
            let formData = new FormData(form);
            let url = "engine/api.php";
            let act = "registration-details-clients";
            fetch(`${url}?act=${act}&=`, {method:'post', body: formData})
                .then(response => response.json())
                .then(data => {
                    var stat = data.stat;
                    var statMsg = data.statMsg;
                    var myData = data.data;

                    if (stat == 'ok') {
                        notify(statMsg, "success");

                    } else {
                        showAlert(statMsg, 'error');
                    }
                })
                .catch((error) => {
                    console.error('Error:', error);
                    showAlert(d.status);
                });
            // END:

        });

but checking debugger and this seems to send a weird payload (raw?)

   -----------------------------20933611634071352467338304530
  Content-Disposition: form-data; name="fname"
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!