码迷,mamicode.com
首页 > Web开发 > 详细

js在URL中传参中文出现乱码

时间:2014-11-27 16:20:24      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:js   乱码   easyui   utf-8   搜索   

最近用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行:

<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>则会出现中文乱码。



此乱码还有一种解决方案:

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

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

不过,第一种方法比较推荐,直接在配置里配置一下方便。


js在URL中传参中文出现乱码

标签:js   乱码   easyui   utf-8   搜索   

原文地址:http://blog.csdn.net/chenglinping/article/details/41546649

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!