'How do i solve this node.js error when im calling it with jQuery?
I have this assignment and I'm a bit stuck.
When I press the button on the site the console I get this error:
GET http://localhost:3000/getUser 404 (Not Found) jquery-1.12.4.js:10254
Can anyone tell me what I'm doing wrong? I am new to node and our teacher didn't even have any lessons on it just expects us to know it I'm thankful for any answers I get
Here is my code:
Script.js
$(document).ready(() => {
$("#btn_prijava").click( () => {
$.post('getUser', (uporabnik) => {
console.log("Works");
});
});
});
app.js
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
const fs = require('fs');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
const { request } = require('http');
var app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.post('/getUser', (req, res) => {
res.send("User");
});
app.listen(3000, () => {
console.log("App je pognan");
});
module.exports = ap
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|