user269964 user269964 - 1 year ago 83
Node.js Question

Bad request Angular Node post by id

I have in my angular code:

$scope.Update = function(){
var data = $.param
Problem: $scope.problem
,description: $scope.description
,resolution: $scope.resolution


$"/kbase/" + $scope._id , data).
success(function(data) { $scope.m_datalist = data; Reset();})
.error(function(data) {console.log(data + "failure");});


I have on my node server this:'/kbase/:m_id', function (req, res) {

I'm getting two errors:
On the client side:

http://localhost:5000/kbase/578e317bf88c311741b16b66 [HTTP/1.1 400 Bad Request 2ms]

on the server side:

Error: invalid json
at Object.exports.error (/Users/ibmtestlab/Documents/workspace/NodeRunJava/node_modules/express/node_modules/connect/lib/utils.js:60:13)
at IncomingMessage.<anonymous> (/Users/ibmtestlab/Documents/workspace/NodeRunJava/node_modules/express/node_modules/connect/lib/middleware/json.js:74:71)
at emitNone (events.js:67:13)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:913:12)
at nextTickCallbackWith2Args (node.js:442:9)
at process._tickCallback (node.js:356:17)
[90mPOST /kbase/578e317bf88c311741b16b66 [33m400 [90m2ms[0m

I'm hoping to at least see hello.


Answer Source

You don't need to manually serialize data with $.param

var data = {
            Problem: $scope.problem
            ,description: $scope.description
            ,resolution: $scope.resolution


$"/kbase/" + $scope._id , data) //pass data as object
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download