javascript - angular $http post: can't get the request parameters -
i'm beginner... creating crud application angular node , mysql
for reason can't data console.log(request.body.name)
or console.log(request.body.description)
505 error.. if print console.log('any message')
gets displayed without error.
i've bind ng-click="editproductcategory()"
on button
bewlow editproductcategory()
method
$scope.editproductcategory = function (){ productcategoryservice.updateproductcategory($scope.productcategorydata, productcategoryservice.getidfromuri()) .success(function (data) { if(data && data.status && data.status == 'successful'){ alert('updated successfully'); } }) .error(function (err, status) { console.log('********************************'); console.log(err); console.log('-------------------------------'); console.log(status); console.log('********************************'); }); }
and here productcategoryservice.updateproductcategory
updateproductcategory: function (productcategory, productcategoryid) { console.log(productcategory.name); console.log(productcategory.description); console.log(productcategoryid); return $http.post('/updateproductcategory', { name: productcategory.name, description: productcategory.description, categoryid: productcategoryid }); }
here route configuration
this.routetable.push({ requesttype: 'post', requesturl: '/updateproductcategory', callbackfunction: function(request, response) { console.log('/******* arrived ********/'); //console.log(request.body.description + " no errors"); //console.log(request.param()); response.json() } }); this.routetable.foreach(function(route){ if(route.requesttype == 'get') { this.app.get(route.requesturl, route.callbackfunction) } else if(route.requesttype == 'post' || route.requesttype == 'post ') { this.app.post(route.requesturl, route.callbackfunction); } else if(route.requesttype == 'delete'){} });
any idea?
$http.post
send data json, if using express, need use bodyparser middleware parse request body.
var express = require('express') var app = express.createserver(); app.use(express.bodyparser());
Comments
Post a Comment