【发布时间】:2016-10-01 19:02:36
【问题描述】:
我通过以下方式将数据从我的 Angular JS 发送到我的节点 API:
Angular 内部:
$http({
method : "POST",
url : '/add',
data : {
"a" : $scope.a,
"b" : $scope.b
}
}).success(function(data) {
$scope.result = data.result;
}).error(function(error) {
$scope.result = 'Invalid data...';
});
在我的 nodejs API 定义中:
exports.execute = function(req, res){
var a = req.body.a;
var b = req.body.b;
var result;
result = Number(a) + Number(b);
var json_responses;
console.log('from api add');
console.log((a));
console.log(b);
console.log(result.toString());
json_responses = {"result" : result.toString()};
res.send(json_responses);
};
当我从浏览器输入值时,API 和角度工作正常,实际值打印在控制台上。
但是,当我尝试使用 POSTMAN 发布数据或使用数据进行 JMETER 负载平衡测试时,控制台会将数据打印为 "undefined"。 我尝试定义数据的方式是:
data={
a : 100,
b : 100
}
data={
"a" : "100",
"b" : "100"
}
data={
"a" : 100,
"b" : 100
}
我错过了什么??
【问题讨论】:
标签: angularjs node.js jmeter postman