Prototype - Object toQueryString() Method



This method 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).

Syntax

Object.toQueryString(obj);

Return Value

Returns an encoded string.

Example

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      
      <script>
         function showResult() {
            var o = { action: 'ship', order_id: 123, 
            fees: ['f1', 'f2'], 'label': 'a demo' };
            alert("URI: " + Object.toQueryString(o) );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      <br />
      <br />
      <input type = "button" value = "Result" onclick = "showResult();"/>
   </body>
</html>

Output

prototype_basic_object.htm
Advertisements