<script src="../static/js/jquery.base64.js"></script>
<script src="../webstatic/js/jquery.min.js"></script>
首先需要明白一点的是:
js前端默认采用utf-16方式编码;
后台数据加密前将数据转成了utf-8格式;
因此解密后需要进行格式转换,从utf-8转为utf-16。 utf8转为utf16:
var utf8to16 = function(str) {
                var out, i, len, c;
                var char2, char3;
                out = "";
                len = str.length;
                i = 0;
                while(i < len) {
                    c = str.charCodeAt(i++);
                    switch(c >> 4)
                    {
                        case 0: case 1: case 2: case 3: case 4: case 5: case 6:case7:
                        // 0xxxxxxx
                        out += str.charAt(i-1);
                        break;
                        case 12: case 13:
                        // 110x xxxx 10xx xxxx
                        char2 = str.charCodeAt(i++);
                        out += String.fromCharCode(((c & 0x1F) << 6) | (char2&0x3F));
                        break;
                        case 14:
                        // 1110 xxxx 10xx xxxx 10xx xxxx
                            char2 = str.charCodeAt(i++);
                            char3 = str.charCodeAt(i++);
                            out += String.fromCharCode(((c & 0x0F) << 12) |
                                ((char2 & 0x3F) << 6) |
                                ((char3 & 0x3F) << 0));
                            break;
                    }
                }
                return out;
            } utf16转为utf8:
var utf16to8 = function(str) {
                var out, i, len, c;
                out = "";
                len = str.length;
                for(i = 0; i < len; i++) {
                    c = str.charCodeAt(i);
                    if ((c >= 0x0001) && (c <= 0x007F)) {
                        out += str.charAt(i);
                    } else if (c > 0x07FF) {
                        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                    } else {
                        out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
                    }
                }
                return out;
            } 内容也是摘自博友,仅供学习参考。
 

Jquery 前端解码base64出现中文乱码的问题解决方案的更多相关文章

  1. Base64 JAVA后台编码与JS前台解码(解决中文乱码问题)

    中文通过Java后台进行Base64编码后传到前台,通过JS进行Base64解码时会出现中文乱码的问题,被这个问题也是困扰了几天,使用jquery.base64.js只能转码非中文字符,经过搜集各种方 ...

  2. jquery的ajax()函数传值中文乱码解决方法介绍

    jquery的ajax()函数传值中文乱码解决方法介绍,需要的朋友可以参考下 代码如下: $.ajax({ dataType : ‘json', type : ‘POST', url : ‘http: ...

  3. JSP 中文乱码显示处理解决方案

    来源: <http://blog.csdn.net/joyous/article/details/1504274> JSP 中文乱码显示处理解决方案 分类: 所有 Web前端 J2EE20 ...

  4. Request和Response中文乱码问题的解决方案和区分

    首先,在刚接触这个中文乱码问题的时候,还是比较混乱的,因为针对request和response各自都有自己的解决方案,而且思路相似,方法也很相似,又针对get和post两种提交方式,分两种解决中文乱码 ...

  5. RStudio中,出现中文乱码问题的解决方案

    RStudio中,出现中文乱码问题的解决方案解决步骤:1.设置RStudio文本显示的默认编码:RStudio菜单栏的Tools -> Global Options2.选择General -&g ...

  6. VIM、GVIM在WINDOWS下中文乱码的终极解决方案

    文章转自:http://www.liuhuadong.com/archives/68 vim.gvim在windows下中文乱码的终极解决方案在windows下vim的中文字体显示并不好,所以我们需要 ...

  7. vim、gvim 在 windows 下中文乱码的终极解决方案

    vim.gvim 在 windows 下中文乱码的终极解决方案 vim ~/.vimrc 然后加入: " Gvim中文菜单乱码解决方案 " 设置文件编码格式 set encodin ...

  8. jsp中文乱码六种情况---解决方案

    转 jsp中文乱码六种情况---解决方案 2016年10月22日 21:32:55 阅读数:10672 来源:http://blog.csdn.net/lovesummerforever/articl ...

  9. jquery在ie浏览器下中文乱码的问题

    用jquery的ajax方法在调用后台数据发现中文乱码,无法解析中文的url,而在别的浏览器下面就不会,如下所示 $.ajax({ type:'get', url:'薛之谦-演员.lrc', asyn ...

随机推荐

  1. Linux 工作管理 (job control)

    fg , bg 有时,命令需要很长的时间才能执行完成.对于这种情况,我们使用‘bg’命令可以将任务放在后台执行,而用‘fg’可以调到前台来使用. 我们可以通过‘&’在后台启动一个程序: fin ...

  2. sleep(0) 的作用

    思考下面这两个问题: 假设现在是 2019-5-18 12:00:00.00,如果我调用一下 Thread.Sleep(1000) ,在 2019-5-18 12:00:01.00 的时候,这个线程会 ...

  3. 【转帖】PostgreSQL之 使用扩展Extension

    PostgreSQL之 使用扩展Extension https://www.cnblogs.com/lnlvinso/p/11042677.html 挺好的文章.自己之前没有系统学习过 扩展.. 目前 ...

  4. 1.3.3 并发容器类MAP/LIST/SET/QUEUE

    HashMap 下标计算方法:hashCode & (length-1) ,&按位与操作,二进制相同位都是1,该位才为1 JDK1.7与JDK1.8中HashMap区别: JDK1.8 ...

  5. javaweb项目的全局监听配置

    在项目中有时候会遇到全局监听的需求,而全局性的监听该如何配置,代码如下: package com.demo.listener; import javax.servlet.ServletContextE ...

  6. Technocup 2020 - Elimination Round 1补题

    慢慢来. 题目册 题目 A B C D tag math strings greedy dp 状态 √ √ √ √ //∅,√,× 想法 A. CME res tp A 题意:有\(n\)根火柴,额外 ...

  7. php源码安装执行configure报错error: off_t undefined; check your library configuration

    php安装执行configure报错error: off_t undefined; check your library configuration vim /etc/ld.so.conf 添加如下几 ...

  8. fiddler笔记:统计选项卡(Statistics)

    Request Count 选中的Session数. Bytes sent Http请求头和请求体中向外发送的字节总数. Bytes received HTTP请求头和请求体中接收到的所有字节数. R ...

  9. Pygame小游戏练习五

    @Python编程从入门到实践 Python项目练习 十一.显示游戏得分及最高分 创建新类Scoreboard,用以显示得分和最高分. # scoreboard.py import pygame.fo ...

  10. C语言 读取配置文件

    配置文件截图: 读取结果截图: 代码转自:http://www.tuicool.com/articles/Zb2iIn 附代码: // ReadConfig.cpp : 定义控制台应用程序的入口点. ...