Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda