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

180
Visualizações
Javascript AJAX + JQuery posts empty data

I am new to web programming and am struggling with a basic task. I am trying to do a simple POST from my frontend to my backend and with it send data in the form of a JSON object. I specifically do not want to embed my javascript code in my HTML file. Please note that all the code shown is all the code used for this POST purpose, so if it looks like I am missing something I most likely am. My frontend JS code is as follows:

/**/
function Test_Button_Pressed() {
    $.ajax({
        type: "POST",
        url: "/test",
        dataType: "json",
        data: {Name: "Rikus", Value: 123},
        contentType: "application/json",
        dataType: "json",
        success: function (result) {
            console.log(result);
        },
        error: function (err) {
            console.log("Error: ", err); //just use the err here
        }
    });
}

/**/
function Activation_Button_Pressed(Button_ID) {}

/**/
function Button_Pressed(Button_ID) {}

The following is logged in the Chrome console when the backend response was made:

Error: [object Object]

The backend code is as follows:

const Api = require("./Api");

var Communication = {};

/**/
Communication.SetUp = function (PanelApp, DataApp) {
    PanelApp.post('/test', (req, res) => {
        console.log(req);
        console.log(req.params);
        console.log(req.body);
        res.send("Done");
    });
};

module.exports = Communication;

Bothe the

console.log(req.body)

and

console.log(req.params)

returns: {}

so from what I can see my routing is correct, it's only my data sending that does not work. Please help and thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

After some help the working code is as follows:

Frontend:

/**/
function Test_Button_Pressed() {
    $.ajax({
        type: "POST",
        url: "/test",
        dataType: "json",
        data: {Name: "Rikus", Value: 123},
        dataType: "json",
        success: function (result) {
            console.log(result);
        },
        error: function (err) {
            console.log("Error: ", err); //just use the err here
        }
    });
}

/**/
function Activation_Button_Pressed(Button_ID) {}

/**/
function Button_Pressed(Button_ID) {}

Backend

const Api = require("./Api");

var Communication = {};

/**/
Communication.SetUp = function (PanelApp, DataApp) {
    PanelApp.post('/test', (req, res) => {
        console.log(req.body.Name);
        console.log(req.body.Value);
        res.json("Done");
    });
};

module.exports = Communication;
about 4 years ago · Juan Pablo Isaza Relatório
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