Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda