[英]How to get object from Request POST object with Angular Ajax call in NODEJS?
After click the button will call a method .. The code is, 点击后按钮会调用一个方法..代码是,
.controller('templeDetailsList', function ($scope, $http, $ionicModal) { $scope.starclick = function(){ var newFav = [{ "favid":"4654646", "favname":"sometext" }]; var favurl = "http://localhost:1337/users/adduser"; $.post(favurl, newFav, function () { alert("Successfully posted data"); }); } });
Node service with mongodb code is, 使用mongodb代码的节点服务是,
var express = require('express'); var router = express(); router.post('/adduser', function (req, res) { var db = req.db; var d1 = req.body; var collection = db.get('userlist'); collection.insert(req.body, function (err, result) { res.send( (err === null) ? { msg: '' } : { msg: err } ); }); });
Http request succesfully worked for to calling service method. Http请求成功地用于调用服务方法。 But i can't get request object in service method. 但我无法在服务方法中获取请求对象。 What can i do for this?. 我能为此做些什么? I want get requesting object data in service method. 我想在服务方法中获取请求对象数据。 please anyone help to me. 请任何人帮助我。
Add body parser to your express app. 将身体解析器添加到您的快速应用程序
var router = express();
bodyParser = require('body-parser');
router.use(bodyParser.json());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.