我是AngularJS的新手。
我在尝试从AngularJS调用PUT restful webservices时遇到错误。这是我的工厂方法。
normal mapping
EmployeeService是我的服务名称
.factory('EmployeeService',function($q,$http){
Approval:function(userId,firstName){
var deferred = $q.defer();
$http({
method: 'PUT',
url: '/AngularExample/user',
params:{
lastName:userId,
firstName:firstName
}
}).
success(function (data) {
if (data != null || data != 'undefined') {
deferred.resolve( data);
}
})
.error(function (error) {
console.log('error');
});
return deferred.promise;
})
这是在Java中调用PUT REST Api调用时出错。
$scope.showAlert = function () {
EmployeeService.Approval( $stateParams.userId,$stateParams.firstName).then(function (approval) {
$scope.approve= approval;
})
它适用于Postman。
答案 0 :(得分:0)
i am using service and simple call the our REST API
//in app/js
var serverUrl = 'http://xxxxx.in/api';
.service('UserBankDetails', ['$http',
function($http) {
this.userBankDetailsAdd = function(data, cb) {
var res = $http.put(serverUrl + "/user_bank_account", data);
res.success(function(data, status, headers, config) {
cb(data);
});
}
}
])
//simple call from controller
UserBankDetails.userBankDetailsAdd($scope.userBankInfo, function(res) {
console.log(res);
if (res.data === 1) {
$scope.account_found = true;
} else {
$scope.account_found = false;
}
});