help to deal with the problem, the post request does not reach the server and hangs on hold. I use stack of angularjs + expressjs

post request on client:

$http({ method: 'POST', url: '/api/message', headers: {'Content-Type': 'application/json'}, data: {msg: $scope.message} }). success(function(response) { console.log("Success " + JSON.stringify(response)); }). error(function(response) { console.log("Error " + JSON.stringify(response)); }); 

server:

 app.post('/api/message', function(req,res) { var message = new Message(req.body); message.save(); res.status(200); }) 

I receive this message in the console:

 Request URL:http://localhost:3000/api/message Request Headers Provisional headers are shown Accept:application/json, text/plain, */* Content-Type:application/json Origin:http://localhost:3000 Referer:http://localhost:3000/? User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36 Request Payload view source {msg: "231313"} msg:"231313" 
  • Try to display the server req.body on the server, and open the project in another browser. - MrFylypenko
  • the message “231313” is displayed on the server in the console, but the pending status still hangs, because of this, the message is not recorded in the database, it is not clear what they did wrong .. - daydreams
  • The request turns out reaches the server. Maybe the problem with saving to the database? Do not write to the database, but simply return the status of 200 to the browser, or the same message. - MrFylypenko
  • app.post ('/ api / message', function (req, res) {var message = new Message (req.body); message.save (); res.status (200);}) here I am I return the status 200, but then why he does not write to the database when the same req.body is displayed in the console .. ps I work with md through mongoose - daydreams
  • one
    Instead of res.status(200) try res.status(200).send() , this will definitely send the answer to the browser. Why not save? It is necessary to add a function inside the save(function...) method, look in the documentation better. - MrFylypenko

0