marifemac marifemac - 4 months ago 25
Javascript Question

How can I convert javascript json data to be x-www-form-urlencoded?

I need to send data to my server with a content type of this:

'Content-Type': 'application/x-www-form-urlencoded'

Here's the data that I have from my AngularJS client:

user.loginData = {
userName: "",
password: "smith++"

Can someone help by telling me how I can transform the userName and password so I can
send this data in a urlencoded form to my server:

data: 'grant_type=password&username=' + username + '&password=' + password,


I found a very simple solution: