jQuery使用serialize()表单序列化时出现中文乱码问题&js获取url中的参数,并保证获取到的参数不乱码


序列化中文时之所以乱码是因为.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();


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM