class method Object.toQueryString
Object.toQueryString(object) → String
-
object
(Object
) – The object whose property/value pairs will be converted.
Turns an object into its URL-encoded query string representation.
This is a form of serialization, and is mostly useful to provide complex
parameter sets for stuff such as objects in the Ajax
namespace (e.g.
Ajax.Request
).
Undefined-value pairs will be serialized as if empty-valued. Array-valued
pairs will get serialized with one name/value pair per array element. All
values get URI-encoded using JavaScript's native encodeURIComponent
function.
The order of pairs in the serialized form is not guaranteed (and mostly irrelevant anyway) — except for array-based parts, which are serialized in array order.
Examples
Object.toQueryString({ action: 'ship', order_id: 123, fees: ['f1', 'f2'], 'label': 'a demo' })
// -> 'action=ship&order_id=123&fees=f1&fees=f2&label=a+demo'