2016-05-15 11 views
0

のプロパティを読み取ることができません '名前' 私は現在expressJSから以下のエラーを取得し、nodeJSとexpressJSに新しいです:Expressjs POSTエラー:例外TypeError:未定義

TypeError: Cannot read property 'name' of undefined 
at C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\server.js:37:31 
at callbacks (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\express\lib\router\index.js:161:37) 
at param (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\express\lib\router\index.js:135:11) 
at pass (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\express\lib\router\index.js:142:5) 
at Router._dispatch (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\express\lib\router\index.js:170:5) 
at Object.router (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\express\lib\router\index.js:33:10) 
at next (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\express\node_modules\connect\lib\proto.js:199:15) 
at C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\body-parser\lib\read.js:107:5 
at IncomingMessage.onEnd (C:\Users\jitheshlive\IdeaProjects\nodejs-express-start\node_modules\body-parser\node_modules\raw-body\index.js:136:7) 
at IncomingMessage.g (events.js:260:16) 

マイexpressJSコードは以下の通りです:

app.configure(function(){ 

app.use(express.logger()); 

app.use(express.static(__dirname + '/app')); 

app.use(bodyParser.json()); 

app.engine('html',engines.underscore); 
/* 
Set views direcoctory. DO NOT set this with the static directory!. 
*/ 
app.set('views', __dirname+'/app/views'); 
app.set('view engine', 'html'); 

app.set('PORT',config.server.port); 
}); 

app.get("/", function(req,res){ 
res.render('index'); 
}); 

app.post("/webservice-1.0/rest/student/add/", function(req,res){ 
    console.log(req.param.student.name); 
    console.log(req.param.student.address); 
//res.render('index'); 
}); 

UIでangularJSを使用してデータを送信しています。マイangularJSコントローラは以下の通りである:これは何のreq.param.student.nameがないことを意味

mainApp.controller("addStudentController", function($scope,$http) { 
var resData = {}; 
$scope.output = ""; 
var url = "/webservice-1.0/rest/student/add/"; 
$scope.addStudent = function(){ 
    $http.post(url, $scope.student) 
    .success(function(data, status, headers, config) { 
     resData = angular.fromJson(data); 
     $scope.output = "Student entered successfully with unique Id "+resData.id; 
    }).error(function(data, status, headers, config) { 
     resStatus = status; 
     $scope.output = "Something went wrong. Please try again later." 
    }); 
} 
}); 

答えて

0

。クライアント側からサーバ側に来ているかを確認するには、単に実行します。あなたがリクエストボディ、ないのparamsでデータを送っている

console.log(req.body)

req.body.data.nameまたはreq.body.data.student.nameのようなものがあります。

+0

ありがとうございます。 req.body.data.nameが私のために働いた。 –

関連する問題