js在URL中傳參中文出現亂碼

來源:互聯網
上載者:User

js在URL中傳參中文出現亂碼

最近用easyUI做一個下拉框,在輸入某值後根據某值模糊查詢:

$('#comboboxA').combobox({
url:basePath+'form/formListForCombobox',
method:'get',
valueField:'formId',
textField:'formDisplayName',
panelHeight:200,
multiple:false,
keyHandler: {
up: function (e) { //【向上鍵】押下處理
},
down: function (e) { //【向下鍵】押下處理
},
enter: function (e) { //【斷行符號鍵】押下處理
var inputText = $('#comboboxA').combobox('getText');
var url = basePath+'form/searchFormList'+'?inputText='+ inputText;
$('#comboboxA').combobox('reload',url);
$('#comboboxA').combobox('setValue',inputText);
/*$.ajax({
type:'post',
url:basePath+'form/searchFormList',
data:{'inputText':inputText},
dataType:'json',
success:function (formOptionList){
console.log(formOptionList);
},
error: function(result) {
if(result != 'null' && result != ''){
$.messager.alert("提示", "出現未知錯誤!");
}
}
});*/
},
query: function (keyword) { //【動態搜尋】處理
}
}
});

其中的var url = basePath+'form/searchFormList'+'?inputText='+ inputText;

這一行用到了get方式傳參(url後面直接跟參數為get方式,將參數放在data{"inputText":"inputText"}為post方式傳參)。

而如果沒有配置Servers\Tomcat v7.0 Server at localhost-config\server.xml的約64行:

則會出現中文亂碼。



此亂碼還有一種解決方案:

js中:var url = basePath+'form/searchFormList'+'?inputText='+ encodeURI(inputText,"UTF-8");

controller中: String inputTextVal = new String(inputText.getBytes("ISO-8859-1"),"UTF-8");

不過,第一種方法比較推薦,直接在配置裡配置一下方便。


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.