Ajax POST请求将undefined发送到Express

时间:2016-10-01 17:56:07

标签: javascript ajax node.js express

我试图发送一些要解析的数据。客户端的脚本如下:

router.post("/create", function(req, res){

console.log(req.body);
console.log(req.body.url);
var url = req.body.url; }

在我的快递应用上,在其中一台路由器上,我得到了:

ApplicationWindow {

 Location {
        id: mapCentre
        coordinate {
            latitude: -27.5
            longitude: 153.1
        }
    }
    Map {
        id: map
        anchors.centerIn: parent;
        anchors.fill: parent
        zoomLevel: 11
        objectName: "mainMap"

        function recenter(lat,lng) {
           mapCentre.coordinate.latitude = lat
           mapCentre.coordinate.longitude = lng
         }
     }
}

我得到了#undefined',然后是“无法获取财产”的网址'未定义的'。

我无法弄清楚我哪里出错......

1 个答案:

答案 0 :(得分:3)

您需要使用bodyParser

app.js:

var bodyParser = require('body-parser')
  , app = express();

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
相关问题