Do you know a fast and simple way to encode a Javascript Object into a string
that I can pass via a GET
Request?
No jQuery
, no other frameworks - just plain Javascript :)
Do you know a fast and simple way to encode a Javascript Object into a string
that I can pass via a GET
Request?
No jQuery
, no other frameworks - just plain Javascript :)
With Node.js v6.6.3
Reference: https://nodejs.org/api/querystring.html
I have a simpler solution that does not use any third-party library and is already apt to be used in any browser that has "Object.keys" (aka all modern browsers + edge + ie):
In ES5
In ES3
ok, it's a older post but i'm facing this problem and i have found my personal solution.. maybe can help someone else..
Here's the coffeescript version of accepted answer. This might save time to someone.
Here's a one liner in ES6:
Do you need to send arbitrary objects? If so, GET is a bad idea since there are limits to the lengths of URLs that user agents and web servers will accepts. My suggestion would be to build up an array of name-value pairs to send and then build up a query string: