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

jQuery使用serialize()表单序列化时出现中文乱码问题的解决办法

时间:2017-01-05 16:46:10      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:edit   数据   decode   tco   comment   编辑器   false   解决办法   中文   

序列化中文时之所以乱码是因为.serialize()调用了encodeURLComponent方法将数据编码了

解决方法就是进行解码

原因:.serialize()自动调用了encodeURIComponent方法将数据编码了

解决方法:调用decodeURIComponent(XXX,true);将数据解码

//商品标签
function tag(url){
var form = $(‘form‘).serialize(); //序列化内容
var shuju = decodeURIComponent(form,true); //将数据解码
alert(shuju);
return false;
if(url.indexOf("?") >= 0){
var newurl = url + $(‘form‘).serialize();
window.location.href = newurl;
}else{
var form = $(‘form‘).serialize();
var shuju = decodeURIComponent(form,true);
alert(shuju);
var newurl = url + ‘?‘ + shuju;
window.location.href = newurl;
}
}
 
  //解决办法:将解码方式unscape换为decodeURI
  //原因:浏览器会将url中的中文参数进行encodeURI编码,所以要通过js使用decodeURI进行解码
  var url = decodeURI(location.href);  //decodeURI() 函数可对 encodeURI() 函数编码过的 URI 进行解码。

  //jq获取百度编辑器的内容
  var test = editor.getContent();

jQuery使用serialize()表单序列化时出现中文乱码问题的解决办法

标签:edit   数据   decode   tco   comment   编辑器   false   解决办法   中文   

原文地址:http://www.cnblogs.com/babyoctopus/p/6252629.html

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