原型 - 雜湊 toQueryString() 方法



此方法將雜湊轉換為其 URL 編碼查詢字串表示。

這是一種序列化形式,主要用於為 Ajax 名稱空間(例如 Ajax.Request)中的物件等內容提供複雜的引數集。

未定義值對將被序列化,就好像它們為空值一樣。陣列值對將針對每個陣列元素序列化為一個名稱/值對。所有值都使用 JavaScript 的原生 encodeURIComponent 函式進行 URI 編碼。

語法

hash.toQueryString();

返回值

返回 URL 編碼查詢字串。

示例

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

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

輸出

prototype_hash_processing.htm
廣告