Express failed to submit the form using ajax. App.post is invalid.

Code

// ajax
$.ajax({
  url: "/process",
  type: "POST",
  data: $(this).serialize(),
  success: function(data) {
    if (data.success) {
      $container.html("<h2>Thank you!</h2>");
    } else {
      $container.html("There was a problem.");
    }
  },
  error: function() {
    $container.html("There was a problem");
  }
});
// app.jsapp.post
app.post("/process", function(req, res){
    if(req.xhr || req.accepts("json,html")==="json"){
        res.send({ success: true });
    } else {
        res.redirect(303, "/thankyou");
    }
});

however, the result is: There was an arguments!
Open FF, and show

clipboard.png
obviously used app.post for request processing, what went wrong? How to solve?

Mar.16,2021

mistakenly placed app.post after the app.use (req, res, next) middleware function, causing app.post to fail to process post requests. Solution: just put app.post in front of the middleware function. follow-up understanding: as long as you return 404, you should think of "what you asked for, you didn't give it to me". So generally speaking, it is the piece of code that processes the request that goes wrong.

Menu