function doFind(default_value){
?var q_bureau_name = document.forms[0].q_bureau_name.value;
?var defpars = '';
?if(default_value != null){
??defpars = '&default_value='+default_value;
?}
?var url = 'customeroperAction.do';
?var pars = 'action=getbureaulist&sname=customerTel.TEL_BUREAU&q_bureau_name='+encodeURI(encodeURI(q_bureau_name))+defpars;????//encodeURI?兩次將文本字符串編碼為一個有效的統一資源標識符 (URI)。
?var my = new Ajax.Request(url,{method: 'post',parameters: pars,onComplete: show});
}
function show(originalRequest)
{
?var BUREAUSPAN = document.getElementById("BUREAUSPAN");
?BUREAUSPAN.innerHTML = originalRequest.responseText;
}
java 相關代碼
String q_bureau_name = Util.filter(request.getParameter("q_bureau_name"));
??q_bureau_name =? java.net.URLDecoder.decode(q_bureau_name, "UTF-8");
?//ajax提交數據(post)的格式默認為utf-8,利用javascript的提供的escape()或encodeURI()方法.在服務器端接收的時候要使用java.net.URLDecoder.decode(value,"UTF-8")方法進行解碼.
js相關知識:
escape 方法
對 String 對象編碼以便它們能在所有計算機上可讀,
escape(charString)
必選項 charstring 參數是要編碼的任意 String 對象或文字。
說明
escape 方法返回一個包含了 charstring 內容的字符串值( Unicode 格式)。所有空格、標點、重音符號以及其他非 ASCII 字符都用 %xx 編碼代替,其中 xx 等于表示該字符的十六進制數。例如,空格返回的是 "%20" 。
字符值大于 255 的以 %uxxxx 格式存儲。
注意 ? escape 方法不能夠用來對統一資源標示碼 (URI) 進行編碼。對其編碼應使用 encodeURI 和encodeURIComponent 方法。
encodeURI 方法
將文本字符串編碼為一個有效的統一資源標識符 (URI)。
encodeURI(URIString)
必選的 URIString 參數代表一個已編碼的 URI。
說明
encodeURI 方法返回一個編碼的 URI。如果您將編碼結果傳遞給 decodeURI,那么將返回初始的字符串。encodeURI 方法不會對下列字符進行編碼:":"、"/"、";" 和 "?"。請使用 encodeURIComponent 方法對這些字符進行編碼。
encodeURIComponent 方法
將文本字符串編碼為一個統一資源標識符 (URI) 的一個有效組件。
encodeURIComponent(encodedURIString)
必選的 encodedURIString 參數代表一個已編碼的 URI 組件。
說明
encodeURIComponent 方法返回一個已編碼的 URI。如果您將編碼結果傳遞給 decodeURIComponent,那么將返回初始的字符串。因為 encodeURIComponent 方法對所有的字符編碼,請注意,如果該字符串代表一個路徑,例如 /folder1/folder2/default.html,其中的斜杠也將被編碼。這樣一來,當該編碼結果被作為請求發送到 web 服務器時將是無效的。如果字符串中包含不止一個 URI 組件,請使用 encodeURI 方法進行編碼。