The HTTP post method in Angular 2 fails to properly send data to request.JSON within a Grails Action

Having trouble retrieving data from request.JSON passed through an Angular 2 HTTP POST method.

The Grails action is being triggered, but the request.JSON is consistently empty {} even when data is passed.

ANGULAR2: HTTP POST Method:

return this.http.post('http://localhost:8080/test/saveStatus', { status: 'Test' })
  .map((response: Response) => response.json());

Grails Action:

class TestController {

    def saveStatus() { 

        def request = request.JSON
        /*
         other codes...
        */
    }

}

Answer №1

Give this snippet a try to send the information to the controller

 sendData() {
            let url = `http://localhost:8080/test/saveInfo`;
            let info = "Test Info";
            let data = JSON.stringify(info);
            return this.http.post(url, data)
                .map(response => response.json())
                .catch(this.handleError);
        }


 def saveInfo([FromBody]string info) { 

        def request = request.JSON
        /*
         additional codes...
        */
    }

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

Error message displaying Angular Service not able to be injected into component: StaticInjectorError in AppModule

I'm currently attempting to inject a SpotifyService service into a SearchComponent component, where the service requires Http as a parameter. Below is my module setup: @NgModule({ imports: [ BrowserModule, FormsModule, RouterModule ], decla ...

The error message "Property <property> is not recognized on the type 'jQueryStatic<HTMLElement>'" is indicating an issue with accessing a specific property within the TypeScript codebase that utilizes Angular CLI, NPM,

My Development Environment I am utilizing Angular, Angular CLI, NPM, and Typescript in my web application development. Within one of my components, I require the use of jQuery to initialize a jQuery plugin. In this particular case, the plugin in question ...

Assigning values to objects based on the types of their properties in Typescript

In my Redux store, I want to create a reducer that can modify any attribute values within the store. Consider the state object defined with specific types: type StoreState = { admins: Admin[]; messages: Message[]; pageInformation: PageInformation; } ...

Ways to store the ID received from an activity in Android

Hey there, I need help figuring out how to save an ID in my app. Every time I minimize the app and then return, the data is shown as NULL. This ID is generated from an activity and it is used to call data via json from the server. ...

Angular - Ensuring correct rendering of a subcomponent with input parameter on the first update

Here is a snippet of code showcasing a list of educations and a component: <cdk-virtual-scroll-viewport itemSize="5" class="list-scroll"> <app-education-item *ngFor="let education of loadedEducations" ...

Using BigQuery to Import a JSON Object as a Text String

Looking for help with parsing a new line delimited JSON file that contains three fields. Two of the fields are strings and the third is a nested JSON object. For example, here is a sample entry: {"val1":"stringvalue1","val2":"stringvalue2","val3":{"i1":78 ...

Displaying outcomes solely based on JSON upon choosing a filter

Goal I aim to only show results once their respective state is chosen. Currently, all results are displayed automatically upon page load. I prefer if nothing is shown initially. Only when a state is selected should the corresponding results appear. Bac ...

Acquire information using AngularJS

This is a demonstration of my service: import { Injectable } from '@angular/core'; import { GenericPostService } from 'app/shared/services/generic.post.service'; @Injectable({ providedIn: 'root' }) export class FaqServic ...

updating the PickerView data based on the selected options from the previous picker view

I am facing an issue with updating the sections in a pickerView based on the course selection. I have two pickerView - one displaying courses and the other showing course sections corresponding to the selected course ID from JSON response. The problem aris ...

The database did not respond, causing the API to resolve without sending a response for the specified endpoint (/api/dates). This could potentially lead to requests becoming stalled in Next

I have been attempting to retrieve a list of dates from my database in a straightforward manner, but unfortunately, I am not receiving any response (even after trying to log the response data to the console). The only feedback I seem to be getting when sel ...

Troubleshooting: WordPress integration with PhoneGap not processing JSON data

I've been following a tutorial and I'm encountering some issues with the examples provided. Despite my attempts to run the examples, I am not seeing any results: app.html <!DOCTYPE HTML> <html> <header> <script src="https:/ ...

What should be done in Android when the app crashes due to incoming HTML content?

If I register using an email and password, the process is successful if the email exists within the domain. However, if a malformed email address like [email protected] is used, it returns HTML and crashes my app. How can I handle this issue? publi ...

Unveiling the mysteries of JSONP in conjunction with AJAX

JSONP allows for bypassing the same origin policy in JavaScript by using <script> tags to load third party data. However, I am uncertain about how JSONP is utilized together with AJAX. My assumption is that: When an AJAX call is initiated, a <sc ...

Encountering a Bad Request 400 error when sending JSON data to a WCF Service through a jQuery DataTables ajax

Having trouble receiving a valid JSON response from a jQuery DataTables.Net ajax POST call to my WCF Services (4.0) service. Despite trying numerous combinations, I am unable to transfer the aoData values to my service. [Apologies for including so much co ...

Using TypeScript and the `this` keyword in SharePoint Framework with Vue

I'm currently developing a SharePoint Framework web part with Vue.js. Check out this code snippet: export default class MyWorkspaceTestWebPart extends BaseClientSideWebPart<IMyWorkspaceTestWebPartProps> { public uol_app; public render(): ...

What is the best way to declare a collection of objects in TypeScript?

Need assistance with TypeScript - Can anyone help? I'm having trouble deciphering the error message in relation to the code snippet below. My goal is to create an array of objects, but it doesn't seem to be working as expected. interface FieldC ...

"An issue with AngularJS ngTable causing a delay in the rendering of Ajax

Struggling with ngTable Setup Having trouble mastering the use of ngTable by going through the ngTable ajax demo. I attempted to follow along with the example as closely as possible, but I'm encountering a deviation in defining an ngResource inline w ...

What are the recommended techniques for utilizing prototypal and prototype-based inheritance in modern JavaScript (ES6) and TypeScript?

Some older discussions on Javascript prototypal inheritance & delegation can be found below: Benefits of prototypal inheritance over classical? classical inheritance vs prototypal inheritance in javascript I am curious about the current (2018) recom ...

Encountering an exception while parsing JSON

I'm trying to extract specific fields from a JSON object. Here is an example of the JSON data- { "id": "100000224942080000", "name": "Tech Geeky", "first_name": "Tech", "last_name": "Geeky", "link": "https://www.facebook.com/tech.geeky ...

When a user logs out, Angular assigns a null value to the User object

Currently, I am in the process of creating a basic user authentication application using Angular by following a helpful tutorial. However, I have encountered an issue while attempting to set null to the User object once the user has logged out. Error: ER ...