Memo: 记的在传递值和取页面返回值的时候编码和解码

不编解码会造成中文乱码的问题, 其中FF会在发送请求时自动进行Encode, 但是IE不会 , 安全的做法就是发送时编码, 接收时解码:

 

//写在Utility里的辅助拓展方法

String.prototype.encodeURIComponent = function () {

    return encodeURIComponent(this);

}

String.prototype.decodeURIComponent = function () {

    return decodeURIComponent(this);
$.ajax({

            type:"GET",

            url:"UserRelationAjaxCall.aspx",

            dataType:"text",

            data:"Type=ManageGroup&GroupStr=" + groupParam.encodeURIComponent(),

            success:function(msg){  

                groupsArray =  msg.decodeURIComponent().split('|');

                generateGroups();

            },

            error:function(msg){

                alert("Error");

            }

        });

后台代码处理时也要加上:

string tempstr = HttpUtility.UrlDecode(Request.QueryString["GroupStr"]);

DoSomething(); //...

Response.Write(HttpUtility.UrlEncode( LoadUserRelationHdValueString() ));

你可能感兴趣的:(返回值)