jquery serialize中文乱码的原因:【serialize()】自动调用encodeuricomponent方法将数据编码了;解决方法:调用“decodeuricomponent(xxx,true);”将数据解码即可。
相关推荐:《jquery视频教程》
本教程操作环境:windows7系统、jquery3.5版本,该方法适用于所有品牌电脑。
在项目中发现用了jquery serialize这个方法后,中文已经转了编码格式的了,以为直接将tomcat的设置为utf-8就可以解决,发现并不是这样的,后来直接上网google一翻,得到以下答案:特记录如下(试过可行)
一:
原因:.serialize()自动调用了encodeuricomponent方法将数据编码了
解决方法:调用decodeuricomponent(xxx,true);将数据解码
例如:
var params = jquery("#formid").serialize(); // http request parameters. params = decodeuricomponent(params,true);
二:
1、将jquery.js文件中的encodeuricomponent替换为encodeuri。即可解决中文乱码。(不知道在哪改,没试过)
2、另一种方式将所有jsp、xml的字符集都设置为utf-8 。(我的这两种文件本来都是utf-8,估计有漏掉的,是否可行未知)
jsp
<%@ page language="java" contenttype="text/html; charset=utf-8"%>
xml
<?xml version="1.0" encoding="utf-8"?>
更多编程相关知识,请访问:编程视频课程!!
以上就是jquery serialize乱码怎么解决?的详细内容。
