您的位置:首页 > 技术中心 > 前端框架 >

jquery post中文乱码怎么办

时间:2020-11-25 14:40

jquery post中文乱码的解决办法:1、前台post请求的时候对发送的数据进行【encodeURIComponent()】编码;2、后台用【UTF-8】转译。

  • 该方法适用于所有品牌电脑

jquery post中文乱码的解决办法:

前台post请求的时候对发送的数据进行encodeURIComponent()编码

例如:

var transactType= $("#transactType").attr("value");
var content=encodeURIComponent($("#content").html());
var title=encodeURIComponent($("#title").val());
$.post(      
"${path}/transact!addTransact.action",
 {"content":content,"title":title},
 function(data){        
   if(data=='1'){           
    alert("保存成功!");           
    DG.cancel();          
  }else{           
    alert("保存失败!");        
  }
}
);

后台:

UTF-8转译

transactType = URLDecoder.decode(getStringParameter("transactType"),"UTF-8");
content =  URLDecoder.decode(getStringParameter("content"),"UTF-8");
title =  URLDecoder.decode(getStringParameter("title"),"UTF-8");

即可解决jQuery post请求中文乱码问题。

相关学习推荐:js视频教程

以上就是jquery post中文乱码怎么办的详细内容,更多请关注www.gxlsystem.com其它相关文章!

本类排行

今日推荐

热门手游