Steps for populating an ng-table with data retrieved from a REST web service that returns a JSON format

I am currently facing an issue while trying to load my table from a JSON response that I receive from REST web services in SpringMVC. The error message I received indicates that my REST method does not support the GET request.

The URL mapped in my controller is:

http://localhost:8080/MyApp/doc/showDocTable/

However, the URL changes unexpectedly to:

http://localhost:8080/MyApp/doc/showDocTable/?count=10&page=1

This change in URL format is puzzling as I am following a basic example from this website

Here is the function within my controller responsible for calling the web services:

var Api = $resource('http://localhost:8080/MyApp/doc/showDocTable/');
            this.tableParams = new NgTableParams({}, {
                getData: function (params) {
                    // ajax request to api
                    return Api.get(params.url()).$promise.then(function (data) {
                        params.total(data.inlineCount); // recal. page nav controls
                        return data.results;
                    });
                }
            });

Additionally, here is the relevant controller method in Spring MVC:

... ...

Any idea what could be causing this unusual URL transformation and subsequently leading to the error?

EDIT 1 I made some modifications to both the backend URL configuration and the AngularJS controller method URL as mentioned below:

@RequestMapping(value = "/doc/showDocTable", method = RequestMethod.GET)
public ResponseEntity<List<HistDoc>> showTable() {
    List<HistDoc> listHistDoc = docDAO.getDocs();

    return new ResponseEntity<List<HistDoc>>(listHistDoc, HttpStatus.OK);
}
var Api = $resource('http://localhost:8080/MyApp/doc/showDocTable');

However, these changes resulted in a new error appearing in the browser console:

Error: $resource:badcfg
Response does not match configured parameter
...    

EDIT 2: Included below is the HTML snippet along with the JSON data returned from the backend:

... ...

Answer №1

To fetch the data, it is recommended to use $resource.query() or Api.query() over $resource.get() and Api.get().

Answer №2

Instead of using Api.get(), try utilizing Api.query(...) to resolve the issue you are experiencing:

The error in the resource configuration for the action get can be resolved by expecting a response that contains an object instead of an array (Request: GET http://localhost:8080/MyApp/doc/showDocTable)

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

ExpressJS - Issue with POST Router resulting in 404 Error

I am currently getting acquainted with ExpressJS and am in the process of setting up a small todo list app while incorporating React. I have successfully retrieved my list of todos from a mysql database, however, I am encountering difficulties with the POS ...

Combining a Browserify AngularJS Module factory with another factory method to enhance functionality

Currently, I am in the process of implementing Browserify into an existing application. One of the requirements is to have a BaseService that includes standard functionalities like setting headers on requests. Within my factories, I utilize loadash to ex ...

Performing a Search Operation using AJAX with Elasticsearch

I've been struggling to find the correct method for requesting data from elasticsearch using a jQuery AJAX call. I keep encountering parsing errors or getting all documents in the index instead of my intended results. $(document).ready(function() ...

Having trouble getting the sorting/search function to work with a click event to display content. It seems to only work with a single item - possibly an issue with the

Creating a function that involves multiple boxes with a search function. The search function is working for the most part, but when clicking on a result, certain content should display. function filterFunction() { var input, filter, ul, li, a, i; ...

How to send a global variable to an event callback function in JavaScript?

I have encountered an issue in the following code where I am attempting to pass mydata to the callback function. This is just a small part of a larger problem that I am facing and I suspect it may be related to scope. Can anyone help me identify what is wr ...

Tips for eliminating redundancy in $scope manipulation code within multiple controllers using angularJS

Apologies if this question seems trivial, but I am just getting started with angularJS. I have created two controllers: seekerController and wizardController... Within the wizardController, there is a Scope object called chat, which is being manipulated ...

Unable to modify the model of the directive

I'm facing an issue where additional elements added to my array within a controller of a directive are not being displayed in the view. What's even more frustrating is that when I print my model, it doesn't reflect the new elements that have ...

While JSON Lint may declare the JSON data as valid, JSON.parse may still encounter an error when trying

I'm struggling to parse a simple JSON object. It's strange because when I check the validity of my JSON string on JSONLint (http://jsonlint.com/), it shows that it's valid. var data = '{"token":"9eebcdc435686459c0e0faac854997f3","email ...

Exploring audio analysis across different platforms using the power of the Web Audio API

Currently, I am in the process of developing an audio visualizer application using the web audio api and the three.js library. Utilizing the html5 element has been effective in extracting audio from local mp3 files or streaming mp3 files through the crea ...

What is the best way to trigger an API call using AJAX whenever the page loads and at regular intervals using `setInterval()` function?

New to coding and seeking guidance: I have a basic AJAX feature in my project that triggers a GET API request every 3 seconds: <script> $(document).ready( function() { setInterval(function() { $.get(&apos ...

Is it possible to retrieve calculated data from a child component and pass it to the parent component?

Is there a way to transfer computed data from a child component to a parent component? Currently, I am passing data from the parent to the child first and then I would like to utilize the computed property (data) in the parent component. This is crucial as ...

Tips on providing validation for either " _ " or " . " (select one) in an Angular application

I need to verify the username based on the following criteria: Only accept alphanumeric characters Allow either "_" or "." (but not both) This is the code snippet I am currently using: <input type="text" class="form-control" [ ...

HTML comments generated from Freemarker's list notation

Currently, I have integrated Apache Freemarker into an HTML editor where users can create templates using code. For example, a user may write the following code for a list: <#list items as item>...</#list> While this is the correct way to gen ...

The $scope update within a function and using $apply does not seem to be functioning properly

One issue I am facing is updating the input value. I have a variable $scope.date_from which is shown in an input[type="date"]. My goal is to change the value by clicking a button. Below is my code snippet: $scope.update_date = function (date_from, date_to ...

Testing with Phantom/Casper in a browser-based environment

Currently, I am utilizing Casper for UI testing on websites. My main concern is regarding the compatibility testing in various browsers such as IE, Chrome, and Firefox using Casper. If this cannot be achieved with Casper, I am open to alternative methods ...

The attempt to generate a .zip file using Node.js with Egg framework was unsuccessful

I developed a Node.js service using Egg framework to send a local .zip file (compressed directory) to the browser, but encountered an issue. Below is the code snippet: Egg.js // Code for zipping files async download() { const ctx = this.ctx; co ...

Tips for enabling both vertical and horizontal scrolling using the mousewheel on a webpage

Our website features a unique scrolling functionality where it starts off vertically and then switches to horizontal once the user reaches the bottom. This allows for a seamless transition between scrolling directions. In addition, users can easily naviga ...

Harnessing the power of service binding in AngularJS

I am utilizing a service to facilitate data sharing between two controllers and retrieve a list of data: myApp.service('DataService', function($http) { this.data = []; this.loadData = function() { $http.get('/api/data') ...

Exploring the capabilities of Vue JS to dynamically update data and model bindings within form

I need help creating a form that allows users to edit their comments. The challenge is to display the current value of the comment using dynamic data from v-for, while also binding the value to a model for sending it with a patch request. Here is an examp ...

retrieve: add elements to an array

I'm having trouble identifying the issue here. I am fetching some json data (using a text file) and trying to push it into an array in the global scope. Even though I iterate over the json and push entries to the array, when I log it out, it appears e ...