简体   繁体   中英

Angularjs POST request status pending

I need your help, dunno no how to solve it, I'm using MEAN stack for simple app, that has a field with input tag inside and when i fill it the data is sending to server and save in db, the problem is that post request cant reach the server.

heres is my post:

    $http({
            method: 'POST',
            url: 'http://localhost:3000/api/message',
            headers: {'Content-Type': 'application/json'},
            data: JSON.stringify({msg: $scope.message})      
        }).

        success(function(response) {
            console.log("Success " + JSON.stringify(response));
        }).

        error(function(response) {
            console.log("Error " + JSON.stringify(response));
        });

server side:

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

    res.status(200);
})

app.get('/api/message', function(req,res) {
    Message.find(function(err,message) {
        if(err) {
            res.send(err);
        } else {
            res.json(message);
        }
    })
})

and this is what i get in browser dev tool

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: "3232"}
  msg:"3232"

Following could be the issue

  • actual request is not being sent from the code or browser is using cached data
  • some adBlocker or some extension is blocking the request
  • try removing http://localhost:3000 from the url

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM