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

86
Vistas
Function is returning curly braces

i've asked very similar question before (Why is it when posting an object into a json file, one of the key/value always appears as curly braces?), and hate asking it again but i can´t find the answer anywhere. So i have this function that returns "hello" (it should return a certain value, but error happens either way, so i have "hello" for testing).

function index(){
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            $("#noteDisplay").on("click", ".remove", (e) => {
                //indexResult = (e.currentTarget.parentNode.id - 1);
                const indexResult = "hello";
                let error = false;
                //-----
                if(!error){
                    resolve(indexResult);
                } else {
                    reject('Something went wrong!');
                }
            });
        }, 2000);
    });
}      

I´m calling this function here.

export default function SendId(){
    React.useEffect(() => {
        /*$("#noteDisplay").on("click", ".remove", async (e) => {
            console.log("ola");
        });*/
        //-----------------------------------------------------
        $("#noteDisplay").on("click", ".remove", async (e) => {
            const PORT = process.env.PORT || 3001;
        
            let index_note = { // the object
                index: await index()
            }
        
            let data = JSON.stringify(index_note);
        
            let xhr = new XMLHttpRequest();
            xhr.open('POST', `http://localhost:${PORT}/api/1`, true);
            xhr.send(data);
            console.log("the data was sent")
        });
        
    });
    return(null);
}

And with or without async await it always retuns curly braces, when i log it. I console.log it this way(but i don't think that's the problem).

app.post("/api/:1", (req, res) =>{
  console.log(req.body);
});

Sorry for the repeating question, and any help would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are not added 'Content-Type': 'application/json' to your request headers. Maybe this is an issue

xhr.setRequestHeader('Content-Type', 'application/json');

about 4 years ago · Juan Pablo Isaza Denunciar
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