这里我需要在滚动中搜索名字,因为我在get调用中发送了搜索数据查询字符串,但我需要在post中发送。
这是我的服务器和客户端控制器的路由和service.Also,我在这里处理从服务器side.How到post数据的搜索,并将其传递给客户端和服务器端。
client controller service:
'use strict';
angular.module('details').factory('DetailService', ['$resource',
function($resource) {
return $resource('details', {
},
searchUsers:{
method: 'GET',
}
});
}
]);
Angular controller:
$scope.searchServer = function(searchData){
DetailService.searchUsers({search:searchData},function(response){
}, function(error){
$scope.status = 'Unable to load customer data: ' + error.message;
});
}
my Server side controller:
exports.searchCust = function (req, res) {
var strWhere = {
corporateName: search
};
db.Customer.findAll({
where: [strWhere],
}).then(function (customers) {
if (!customers) {
return res.status(400).send({
message: 'Customer not found.'
});
} else {
res.jsonp(customers);
}
})
};
my server sideroute:
app.route('/details').all(customersPolicy.isAllowed)
.get(details.searchCust);
app.param('search', details.searchCust);
};发布于 2015-12-17 17:12:16
我没有尝试它的所有细节,因为它看起来是复制和粘贴在一起,而没有阅读基本知识。然而,如果你想要POST请求,你需要在节点代码和角度代码中设置它们,如下所示。更重要的是,Angular不使用JSONP,它使用JSON,所以您需要对其进行设置。在searchUsers资源调用中,您只实现了错误分支,因此结果将会消失。您现在可以在$scope.searchResults中找到它们。
客户端控制器服务:
'use strict';
angular.module('details').factory('DetailService', ['$resource',
function($resource) {
return $resource('details', {},
searchUsers: {
method: 'POST',
}
});
}]);角度控制器:
$scope.searchServer = function(searchData) {
DetailService.searchUsers({
search: searchData
}, function(response) {
$scope.status = "OK";
$scope.searchResults = response;
}, function(error) {
$scope.status = 'Unable to load customer data: ' + error.message;
});
} 我的服务器端控制器
exports.searchCust = function(req, res) {
var strWhere = {
corporateName: search
};
db.Customer.findAll({
where: [strWhere],
}).then(function(customers) {
if (!customers) {
return res.status(400).send({
message: 'Customer not found.'
});
} else {
res.json(customers);
}
})
};my server sideroute:
app.route('/details').all(customersPolicy.isAllowed)
.post(details.searchCust);
app.param('search', details.searchCust);
};https://stackoverflow.com/questions/34312775
复制相似问题