Issue with communication between AngularJS and Spring MVC causing response data not to be received correctly through ngResource

I have configured my application with Spring MVC for backend and AngularJS for frontend. I am encountering an issue with ngresource while making http calls. The response data is not being retrieved properly.

test.js

angular.module('app').factory("testService",

    function($resource) {
        return {
            getdata: $resource('/setupdata',{},
              {
                'save' : {
                method:'POST'
            }
            })  };
    });
    angular.module('app').controller('testController',function($scope, $http,testService) {
    var init = function(){
    testService.getdata.get(function(response) {
    //in response age,height etc is there
    //if I put alert I am getting[Object,Object] and If I put JSON.stringify(data) all the parameters are appearing like age , height etc,If I check with data.age, data.height a blank braces is coming {}.
    } 
    init();
});

The data passed from my Spring MVC is not being received as expected.

Answer №1

When using $resource.get(), the first parameter should be a query parameters object:

userService.getData.get({ userId: 123 }, function(result) {
    console.log(result);
});

You can also pass multiple parameters:

userService.getData.query({}, function(result) {
    console.log(result);
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieving the output from a nested function within a function in a Node.js application connected to a

I'm currently working on a basic web application that interacts with a database by performing INSERT and SELECT operations on a single table. While I have utilized a function from various tutorials, I am struggling to retrieve the results from the SEL ...

Page freezing due to JQuery scroll event

I successfully implemented a trigger that checks if an element is within the visible viewport and added it to the scroll event. While this works smoothly on some pages, I noticed that on larger pages it causes the page to freeze. In Firefox, I experienced ...

Activate on click using JavaScript

When a link with the class .active is clicked, I want to use a JavaScript function to deactivate any other active links. The structure of the code should be as follows: <ul class="product"> <li><a href="#myanmar" class="active">Mya ...

Preventing the lengthy timer task in the latest Chromium Developer Tool

Currently, I am facing a challenge in my Ionic project. The updated Chrome browser is not allowing me to broadcast events as it did before due to the recent update that defers long running tasks. View Code And Screenshot Does anyone have a solution to wor ...

Retrieving text content from a file using React

I've been experiencing difficulties with my fetch function and its usage. Although I can retrieve data from the data state, it is returning a full string instead of an array that I can map. After spending a few hours tinkering with it, I just can&apos ...

Platform error: Responses not specified for DIALOGFLOW_CONSOLE

I've been struggling with this issue for almost a day now and I'm at a loss for what else to try. For some reason, Dialogflow Fulfillment in Dialogflow ES is refusing to make any HTTP calls. Every time I attempt, I receive the same error message ...

Converting wiki content to HTML with the help of PHP and JavaScript

Looking to convert wiki syntax to html? Check out the techniques discussed in this resource: Below is the source code of my php page that appears to be functioning correctly. Feel free to test it out yourself: <? if(!defined('DOKU_INC')) d ...

What is the best way to attach a jQuery UI event handler to a button that has been dynamically generated?

Currently, I have a jquery ui modal dialog box form that inserts items into a table. A specific column in the table contains a button which serves as a link to edit the particular row. My goal is to attach an event handler to this button so that when a use ...

Retrieve all default and user-defined fields associated with contacts in the CRM 2011 system

In CRM 2011, the contact entities come with a variety of default fields, and I have also included some custom fields. My goal is to retrieve all field names in a JavaScript list. When creating an email template in CRM, you can select fields from a dialog. ...

Vue looping through nested checkbox groups

Here is an object I am working with: rightGroups: [ { name: "Admin Rights", id: 1, rights: [ { caption: 'Manage Rights', name: 'reports', ...

Endless loop of jquery textbox focus event

Currently, I am employing jQuery for validating textbox values. I have two textboxes - txt1 and txt2. For this purpose, I have created a jQuery function: $("#txt1").blur(function () { if ($("#txt1").val() == "") { $("#scarrie ...

Dealing with performance issues in VueJS and Vuetify's data-table component, especially when trying to implement

In my VueJS and Vuetify project, I encountered an issue. I am trying to create a table with expandable rows for displaying orders and their associated products. The table needs to show at least 100 rows of orders on one page. To achieve this, I utilized th ...

modal dropdown with overflow in ui-select

Currently, I am encountering an issue with the display of a ui-select dropdown inside a ui bootstrap modal that has overflow css set up. Whenever the ui-select dropdown is opened, the list of options appears within the modal but is partially obscured by t ...

Utilizing unique layouts for specific views in sails.js and angular.js

I am currently working on a Sails.js + Angular.js project with a single layout. However, I have come across different HTML files that have a completely different layout compared to the one I am using. The layout file I am currently using is the default la ...

Vue-ctl project creation halted by operating system rejection

While working on a Vue-CLI project, I encountered an issue. Has anyone else faced this problem before? Operating system: Windows 10 - Command Prompt (admin rights) @vue-cli version: 4.5.4 npm version: 6.14.6 Here is the command I ran: vue create font_ ...

Is there a way to sort through a data object using a state array in React?

I have found a solution! The code below now displays a functioning example. My latest project involves creating a React portfolio with a Filter system. Users can visit the portfolio page and choose filters (web design, development, etc.) to view specific ...

Loop through a collection of unique identifiers for documents and establish event listeners in Firestore

Within my Vuex store, there is an action designed to retrieve a list of uids for followed users from the current user's Firestore UserDataCollection document. The action then processes each uid to extract data that will be displayed on the UI. While t ...

Attach the document for submission from a different source

Utilizing a jQuery DataTable with the capability of containing multiple rows, each row is populated using a modal. Depending on the selected values, each row may or may not have an attachment. This table is located inside a form. The issue arises when atte ...

Function fails to execute after drop-down menu selection

I set up a double drop-down feature and implemented my function calling code. However, after choosing an option from the drop-down menus, the function is not getting executed. The purpose of the code is to trigger a specific function based on the selectio ...

Remove an item using a function embedded within it

I've been grappling with this issue for quite some time now and I'm unable to find a solution. My approach involves Vue(JS). What I'm attempting to achieve is to push notifications into an Object and then present them to the user. Each noti ...