What could be the reason for AngularJS encoding the URLs for my POST parameters?

Take a look at our service's REST client:

self.headers = {
        Accept: 'application/json',
        'Content-Type': 'application/json'
    };

self.loginClient = $resource(self.baseUrl + '/users/login', {
        userId: '@userId',
        password: '@password'
    }, {
        save: {
            method: 'POST',
            headers: self.headers
        }
    });

When using it, I do the following -

AuthService.loginClient.save({
        userId: self.user.email,
        password: self.user.password
    }).$promise.then(function (res) {
        // perform actions
    })

The resulting URL path that the browser accesses is structured like this:

/users/login?password=XXXXXX&rememberMe=false&userId=XXXXXX

I'm wondering if there is an issue causing my POST parameters to be URL encoded. Any insights on what might be wrong here would be greatly appreciated! Please let me know if more information is needed.

Answer №1

To send the data to the action method, update the service in this way

self.headers = {
        Accept: 'application/json',
        'Content-Type': 'application/json'
    };

self.loginClient = $resource(self.baseUrl + '/users/login',  {
        save: {
            method: 'POST',
            headers: self.headers
        }
    });

Invoke it as shown below

AuthService.loginClient.save({},{
        userId: self.user.email,
        password: self.user.password
    })

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

The fusion of game loop and digest cycles by Angular services

I have successfully integrated my custom 2D JavaScript game engine with Angular. This game revolves around the space theme, where the engine takes care of simulating the space environment while Angular manages the trading menus with space stations and othe ...

Discover the Closest Database Pointers on Google Maps Based on My Current Location

Currently, I am in the process of creating a feature where users can enter their postcode or address information and be presented with markers that are nearby. All of my markers are stored in a database. Initially, I planned to retrieve results from MySQL ...

Retrieve the initial data of the AngularJS model upon button click

Previously, I was able to retrieve the initial values of the model using this.model.changed or this.model._previousAttributes in BackboneJS. Now, I am looking to achieve the same functionality in AngularJS, where I can track all changes made to the model ...

Unknown passport authentication method

I'm currently delving into a tutorial on building an authentication system using passport in Nodejs. The guide can be found here. My focus right now is on getting the signup form to function properly, but it keeps throwing this error: Error: Unknown ...

The validation functionality in AngularJS for a form within an ng-repeat loop is not functioning as intended

In my table, I used the <tr> tag repeatedly with ng-repeat="cancellationPercentData in cancellationPercent" Each tr tag contains a form with name and id set using $index See the code snippet below: <tbody> <tr ng-repeat="cancellatio ...

Empty req.params in nested ExpressJS routers

I have a unique routing system that relies on the directory structure of my 'api' folder to automatically configure routes. However, I encountered an issue where the req.params object is undefined in the controller when using a folder name as a r ...

What is the best method for designing a slideshow with a background image on the body

I have been on a quest to find a simple background slideshow that fades images for the body of my website. Despite trying multiple Javascript options and CSS solutions, I have had no success. Someone suggested creating a DIV for the background, but I am ...

Can the `XMLHttpRequest` object stay active when the user switches to a different page?

I am currently facing an issue on my website where users can submit a form using AJAX. The response is displayed in an alert indicating whether the submission was successful or if there were any issues. However, due to the asynchronous nature of this proce ...

Can Google AdWords track conversions on AJAX forms?

We have a situation where a client needs us to integrate their AdWord Conversion tracking code into a landing page after an enquiry form submission. The challenge is that the form operates using AJAX, so there isn't a traditional "landing page" per se ...

In Vue.js, is it possible to nest a <tr> tag inside another <tr> tag?

I've been working on a dynamic table in vue.js, using the code snippet below: <template> <tr class="left-align" v-for="(item,index) in itemList" :key="index.id"> <td>{{item.items}}</td> ...

Is there a way for me to identify when I am "traveling" along the same path?

I want to create a toggle effect where a view is hidden if the user tries to revisit it. This can be useful for showing/hiding modal boxes. Here's the code I attempted: /* Root Instance */ const app = new Vue({ router, watch: { '$route&a ...

Parent window login portal

I have just started learning how to program web applications, so I am not familiar with all the technical terms yet. I want to create a login window that behaves like this: When a user clicks on the Login button, a window should pop up on the same page t ...

Creating a unique Vue.js modal window for every individual product

Currently, I am in the process of creating a small online store using Vue.js. Within this store, I have a variety of products each with unique names and prices. In order to provide more information about each product, I have included a "Details" button. M ...

when successful, refresh the page

I am currently utilizing the following javascript code to load recrefresh.php when the page first loads. Upon executing the ajaxvote function, I aim for the subsequent div to be refreshed: <div class="recrefresh"></div> After attempting to ad ...

JavaScript does not automatically trigger a function when the value of an input field is changed

I am working on a bootstrap modal form that has multiple input fields. One of the input fields contains the names of states and should display the corresponding region in another field. However, when I change the value of the state field, the region value ...

requirements for ng-model

Can anyone assist me with ng-model? I have an input field where users can select values from an array called 'posters'. The selected value appears in the list. By default, the list displays 'The grand tour'. However, if a user enters a ...

When an onClick event is triggered in jQuery, generate a certain number of div blocks based on the available list items, such as image source and heading text

Is it possible to generate input fields dynamically based on a dynamic list with checkboxes, labels, text, images, etc.? I currently have a working solution for checkboxes and labels using the code snippet below: let $checkboxContent = $('.checkboxes ...

Leveraging Angular's capability to import files directly from the assets

I recently installed a library via npm and made some modifications to one of the modules. python.js If I delete the node_modules folder and run npm install, I am concerned that I will lose my changes. Is there a way to preserve these modifications by mov ...

Guide on creating a menu that remains open continuously through mouse hovering until the user chooses an option from the menu

I have a unique scenario where I am working with two images. When the mouse hovers over each image, two corresponding menu bars appear. However, the issue is that when the mouse moves away from the images, the menu disappears. Any suggestions on how to im ...

Is it possible to retrieve the controller path for an AJAX request from within a partial view?

Looking for a solution to fully decouple and reuse a partial view that allows users to select dates and filter results based on those dates. This widget can be used on multiple pages, so I wanted to add event listeners that would submit the form within the ...