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

179
Views
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 answers
Answer question

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 Report
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!