首页 > Web开发 > 详细

Ajax get方式传值乱码问题

时间:2015-06-30 20:17:30      阅读:295      评论:0      收藏:0      [点我收藏+]

我的解决方式是:对需要传递的中文先进行编码:encodeURIComponent(‘你好‘);

<script type="text/javascript">
        function getText(){
            var xhr = getXhr();
            var hello = encodeURIComponent(‘你好‘);
            xhr.open("get","testEncode.do?str="+hello,true);
            xhr.onreadystatechange=function(){
                if(xhr.readyState==4&&xhr.status==200){
                    alert(xhr.responseText);
                }
            }
            xhr.send();
        }
</script>

在后台直接用request.getParameter("str")取即可。

Ajax get方式传值乱码问题

原文:http://www.cnblogs.com/liujunfen/p/4611283.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!