Is there any way to create the query parameters for doing a GET request in Javascript?
Just like in Python you have urllib.urlencode(), which takes in a dict (or list of two tuples) and creates a string like 'var1=value1&var2=value2'
.
Is there any way to create the query parameters for doing a GET request in Javascript? Just like in Python you have urllib.urlencode(), which takes in a dict (or list of two tuples) and creates a string like |
||||
|
Here you go:
Usage:
|
|||||||||||||||||||||
|
fun(ctional)
|
|||||
|
Zabba has provided in a comment on the currently accepted answer a suggestion that to me is the best solution: use jQuery.param(). If I use
The variable
For more complicated examples, inputs and outputs, see the jQuery.param() documentation. |
||||
|
If you are using Prototype there is Form.serialize If you are using jQuery there is Ajax/serialize I do not know of any independent functions to accomplish this, though, but a google search for it turned up some promising options if you aren't currently using a library. If you're not, though, you really should because they are heaven. |
|||||
|
We've just released arg.js, a project aimed at solving this problem once and for all. It's traditionally been so difficult but now you can do:
And reading works:
or getting the whole lot:
and if you care about the difference between |
||||
|
A little modification to typescript:
|
|||
|
This thread points to some code for escaping URLs in php. There's
|
|||||
|