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



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
[email protected]://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</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:16251:16
$RootScopeProvider/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:16069:15
$RootScopeProvider/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:16359:13
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:10791:36
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:10989:7
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.js:10930:1




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



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.




Replied on April 23, 2016
Nice.

Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us