Home  >  Forum  >  JavaScript
Post New Query

"Error: [$resource:badcfg] Error in resource configuration for action `save`. Expected response to contain an object but got an array


joined on
April 13,2016
Asked on April 23,2016
Hi I am new to AngularJS. I am saving data with ngResource and Spring REST.
How to resolve the following error.


"Error: [$resource:badcfg] Error in resource configuration for action `save`. Expected response to contain an object but got an array (Request: POST http://localhost:8080/spring/data/person/22)
http://errors.angularjs.org/1.4.9/$resource/badcfg?p0=save&p1=object&p2=array&p3=POST&p4=http%3A%2F%2Flocalhost%3A8080%2Fspring4-1%2Finfo%2Fperson%2F22
minErr/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:68:12
resourceFactory/</Resource[name]/promise<@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular-resource.js:613:1
processQueue@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:14991:28
scheduleProcessQueue/<@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:15007:27
$RootScopeProvider/this.$get</Scope.prototype.$eval@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:16251:16
$RootScopeProvider/this.$get</Scope.prototype.$digest@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:16069:15
$RootScopeProvider/this.$get</Scope.prototype.$apply@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:16359:13
done@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:10791:36
completeRequest@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:10989:7
requestLoaded@https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:10930:1

joined on
April 13,2016
Replied on April 23,2016

What I am observing is that I have configured URL as 
http://localhost:8080/spring/data/person/:id
and I am expecting 
http://localhost:8080/spring/data/person

to save data but It is picking wrong URL.
Need help
joined on
October 10,2013
Replied on April 23,2016

While using AngularJS ngResource to save data if you do not want to pass id in your URL, then id should no be assigned any value. If id has no value, AngularJS strips the id from URL and URL will be as follows.

http://localhost:8080/spring/data/person

One thing we need to take care while calling 'save', the returned data should be an object not an array of JSON, we should return Spring ResponseEntity with proper HTTP status.

joined on
April 13,2016
Replied on April 23,2016

Nice.

Write Answer









Copyright ©2017 concretepage.com, all rights reserved |Privacy Policy | Contact Us