1
我是AngularJS的新手。PUT/POST在Java中使用AngularJS嘗試Rest api調用不起作用
我在嘗試從AngularJS調用PUT restful webservices時出現錯誤。這是我的工廠方法。
.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;
})
的EmployeeService是我的服務名稱
$scope.showAlert = function() {
EmployeeService.Approval($stateParams.userId,$stateParams.firstName).then(function (approval) {
$scope.approve= approval;
})
這是獲得同時呼籲在Java中把REST API調用的錯誤。
Angular JS version using :1.3.15 .
Rest api call is not triggering from angular to Rest Back end and not getting any error in back End.
Error getting in the angular js :
unexpected Request PUT No more request expected
at $httpBackend (angular-mocks.js:1180)
at m (angular.js:9628)
at $get.f (angular.js:9344)
at angular.js:13189
at l.$get.l.$eval (angular.js:14401)
at l.$get.l.$digest (angular.js:14217)
at l.$get.l.$apply (angular.js:14506)
at HTMLButtonElement.<anonymous> (ionic-angular.js:9958)
at HTMLButtonElement.c (angular.js:3014)
at triggerMouseEvent (ionic.js:2804)
它在郵遞員工作。
Web服務是工作在郵遞員其餘客戶端鉻 –
您是否嘗試添加服務的完整URL,而不是/ AngularExample /用戶? – anbuj
你是否在你的HTML中包含angular-mocks?不要那樣做 – thomaux