In general, I spent half a day and did not solve the problem! The form is created dynamically.

public / js / main.js

var answerOrQuestion = ''; answerOrQuestion += '<form method="post" action="" id="answerOrQuestionContainer"><div class="rasporka"></div><hr>'; answerOrQuestion += '<p><input type="text" name="Name" placeholder="Name" /></p>'; answerOrQuestion += '<p><textarea name="answer" placeholder="Your answer"></textarea></p>'; answerOrQuestion += '<input type="submit" value="Post Your Answer" />'; answerOrQuestion += '</form>'; $('.container').append(answerOrQuestion); 

Form processing:

  $('.container').on("submit", '#answerOrQuestionContainer', function(event) { event.preventDefault(); $.post("/question/saveQuestion", function (result) {}); }); 

app.js

 var question = require('./routes/question'); app.get('/question', question); 

routes / question.js

 router.post('/saveQuestion', function(req, res) { /* что-то делаем */ }); 

And we get 404 when trying to send a request! Does anyone have any suggestions ?! Thank you in advance

    1 answer 1

    The form is OK, because the request is sent.
    The fact that the page was not found suggests that something is amiss on the server. And indeed, you incorrectly initialize the router. It should be like this: app.use('/question', question);
    Documentation .

    • thank you friend!) I don’t know how I got so fucked up!)) half a day, really half a day)))))) - sparcmen