asp.net+js乱码、flash调用js乱码总结

来源:互联网 发布:jdbc连接数据库的接口 编辑:程序博客网 时间:2024/05/17 00:08
asp.net乱码

1.flash调用页面js显示乱码

flash返回的信息调用
private function myUrlEncode(str:String,code:String):String
        {
            var stringresult:String = "";
            var byte:ByteArray =new ByteArray();
            byte.writeMultiByte(str,code);
            for (var i:int; i<byte.length; i++)
            {
                stringresult +=  escape(String.fromCharCode(byte[i]));
            }
            return stringresult;
        }

进行编码。

调用方式:myUrlEncode(str, "utf-8");

js方法:
function FlashCall(str) {
        viewmsg(decodeURI(str));
    }

使用:decodeURI解码

2.asp.net调用页面上js显示乱码

asp.net后台使用:
HttpUtility.UrlEncode("你好!", System.Text.Encoding.UTF8);
编码为utf-8

js方法:

function showMsg(strMsg) {
            $("#notice").html(JsdecodeURI(strMsg));
        }

使用JsdecodeURI方法解码,JsdecodeURI方法如下:

function JsdecodeURI(str) {
            var backstr = "";
            backstr = decodeURIComponent(str).replace(/\+/g, " ");
            return backstr;
        }

先调用decodeURIComponent方法解码utf-8的编码,在全部替换所有+号为空格,

这里不知道为什么+没有被解码!如果后台要使用+号就用全角的+号吧
原创粉丝点击