JavaLike 发表于 2013-1-29 13:34:13

jquery表单formSerialize方法乱码问题解决

在调用
$('#downloadAttrForm').formSerialize();
时,参数传至后台经常会出现乱码,无论是中文还是时间格式等,解决方法如下所示:
1、因为jquery在调用formSerialize()方法时,内部会自动encodeURIComponent方法,因此在Jsp页面中调用formSerialize()方法后,还需调用decodeURIComponent方法,示例如下所示:
var queryStringTmp = $('#downloadAttrForm').formSerialize();
   queryStringTmp = decodeURIComponent(queryStringTmp,true);
2、在后台处理传过来的参数时,添加以下代码:
java.net.URLDecoder.decode(params , "UTF-8");

经过这两个步骤就可以解决乱码的问题了!!
页: [1]
查看完整版本: jquery表单formSerialize方法乱码问题解决