marifemac marifemac -5 years ago 199
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,

Answer Source

I found a very simple solution:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download