[英]How to send data using $http GET method in angular js?
I need to send emailId as data from angularjs controller to nodejs. 我需要将emailId作为数据从angularjs控制器发送到nodejs。 I googled it but I didn't get solution, someone please help me. 我用谷歌搜索,但没有得到解决方案,请有人帮我。
controller file: 控制器文件:
function ManageProductController($http, $scope, $mdDialog, $document, $location, $localStorage)
{
var vm = this;
vm.email = $localStorage.email;
$http({
url: 'http://localhost:7200/api/manage-product',
method: 'GET',
data: {email:vm.email}
}).success(function(res) {
//$scope.productlist = res;
//console.log(res.result);
vm.result=res.result;
//vm.docs=res.docs;
}, function(error) {
console.log(error);
alert('here');
});
}
In the above code I have sent email
as data but in node.js file I am not getting in request. 在上面的代码中,我已将email
作为数据发送,但是在node.js文件中,我没有收到请求。
node file: 节点文件:
router.get('/manage-product', function(req, res){
//console.log('I received get request');
console.log(req);
var findProducts = function(db, callback) {
var cursor =db.collection('proInfo').find().toArray(function(err, docs){
if(err){
callback(new Error("Some problem"));
}else{
callback(null,docs);
}
});
};
}
Here I have put console.log(req);
这里我放了console.log(req);
but in the body section I am getting only body{}
like this. 但在“正文”部分中,我只得到像这样的body{}
。
With GET
you can make use of params
and at server you can get that value in req.query
see following sample: 使用GET
您可以利用params
而在服务器上,您可以在req.query
获取该值,请参见以下示例:
$http({
url: 'http://localhost:7200/api/manage-product',
method: 'GET',
params: {email:vm.email} //at server it will be req.query.email
}).success(function(res) {
//access returned res here
}, function(error) {
//handle error here
});
With POST
you can make use of data
and at server you can get that value in req.body
see following sample: 通过POST
您可以利用data
而在服务器上,您可以在req.body
获取该值,请参见以下示例:
$http({
url: 'http://localhost:7200/api/manage-product',
method: 'GET',
data: {email:vm.email} //at server it will be req.body.email
}).success(function(res) {
//access returned res here
}, function(error) {
//handle error here
});
send data like this below the url with comma 在网址下方用逗号发送这样的数据
url: 'http://localhost:7200/api/manage-product',
method: 'GET',
params: {emailData:yourEmaildata}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.