So I have this functionality. The client is sending data through jquery post function
$.post(currentURL + "/api/tables", newReservation,
function(data) {
if (data == true) {
alert("Yay! You are officially booked!")
}
if (data == false) {
alert("Sorry you are on the waitlist")
}
$('#reserve_name').val("");
$('#reserve_phone').val("");
$('#reserve_email').val("");
$('#reserve_uniqueID').val("");
});
Then Node.js is receiving it here
app.post("reserve/api/tables", function(req, res) {
var newentry = req.body;
console.log(newentry);
entries.push(newentry);
res.json(newentry);
});
However, console.log
is giving me this error
jquery.js:9631 POST http://localhost:8080/api/tables 404 (Not Found)
Because you are doing the request to the url: http://localhost:8080/api/tables , but your server is waiting you at : "reserve/api/tables".
Try to target: http://localhost:8080/reserve/api/tables
your routing specifies a localhost:8080/reserve/api/tables,
remove the 'reserve' routing
You are missing leading slash in
app.post("reserve/api/tables", function(req, res) {
so it should be
app.post("/reserve/api/tables", function(req, res) {
or
app.post("/api/tables", function(req, res) {
as edited later
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.