Tutorials Point

  Learn Prototype
  Prototype Resources
  Selected Reading

Copyright © 2014 by tutorialspoint

  Home     References     Discussion Forums     About TP  

Prototype Hash toQueryString() Method

previous next AddThis Social Bookmark Button


This method turns a hash 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.


hash.toQueryString() ;

Return Value :

  • Returns a URL-encoded query string.


<title>Prototype examples</title>
<script type="text/javascript" 

function showResult(){

 var h = $H({action:'ship',order_id:123,fees: ['f1', 'f2']});
 alert( "h.toQueryString() : " + h.toQueryString() );




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


To understand it in better way you can Try it yourself.

previous next Printer Friendly