2013-01-11 49 views
0

我編碼URL的使用JavaScript的當表單提交encodeURIComponent()功能:的Javascript decodeURIComponent()與PHP

<form name="form" action="actions.php" method="post"> 

     <input type="text" name="url" id="url" value="http://"> 

     <script type="text/javascript"> 

     function encodeLinks(){ 
      var e = document.getElementById('url') 
      e.value = encodeURIComponent(e.value);   
     } 

     </script> 

     <button type="submit" class="btn btn-primary" onclick="encodeLinks()">Submit</button> 
    </form> 

什麼是最有效的方式來獲得這些數據返回到行動網頁JavaScript才能解碼它,然後在mysql查詢中使用它?

+1

* urldecode *這是你在看什麼? –

+0

爲什麼你需要這樣做?提交表單時,輸入會自動編碼。 – Barmar

回答

1

這樣做毫無意義。瀏覽器將自動編碼您發送的數據,服務器將自動對其解碼。一切都是透明的,所以你根本不需要擔心。