Answer the question
In order to leave comments, you need to log in
Receiving ajax request in nodeJS server?
Dear Experts! A question. As a training, I'm trying to send an ajax request from the client to the express server on the local server, but in the console I get empty quotes, that is, the data does not reach (I use axios)
const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.set("view engine", "ejs");
app.use(express.static("public"));
app.use(bodyParser.urlencoded({ extended: false}));
app.get("/", (req, res) => {
res.render("index");
console.log(req.body);
});
app.post("/", bodyParser, async (req, res) => {
console.log(req.body);
res.render("index");
});
app.listen(3000);
new Vue({
el: ".app",
data: { city: null },
methods: {
async submit() {
const response = await axios({
method: "post",
url: "/",
data: {
body: this.city
}
});
}
}
});
Answer the question
In order to leave comments, you need to log in
This is how you send empty data) you are literally sending null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question