在后台调用了C#的Server.UrlEncode(url),然后get页面,前台javaScript调用decodeURI(url)得到的结果与编码之前的不一致?

解决方案 »

  1.   

    Server.UrlEncode("../SvgFolder/1/20101103/1机组EXTR HTR系统画面.svg")
    结果是
    "..%2fSvgFolder%2f1%2f20101103%2f1%e6%9c%ba%e7%bb%84EXTR+HTR%e7%b3%bb%e7%bb%9f%e7%94%bb%e9%9d%a2.svg"decodeURI("..%2fSvgFolder%2f1%2f20101103%2f1%e6%9c%ba%e7%bb%84EXTR+HTR%e7%b3%bb%e7%bb%9f%e7%94%bb%e9%9d%a2.svg")
    结果是
    "..%2fSvgFolder%2f1%2f20101103%2f1机组EXTR+HTR系统画面.svg"
      

  2.   

    首先看在要现在后台用相关函数转码,然后再在js这面解码(还是相关函数,c#不太了解,你baidu下),至于像'/'这样的就在js里替换
      

  3.   

    类似
    function text_replace(text){
    var l = text.length;
    for (var i = 0; i < l; i++) {
    if (text.charAt(i) == "%"){
    if(text.charAt(i+1) == "2"){
    if(text.charAt(i+2) == "3")text = text.replace("%23","#");
    if(text.charAt(i+2) == "4")text = text.replace("%24","$");
    if(text.charAt(i+2) == "6")text = text.replace("%26","&");//&&
    if(text.charAt(i+2) == "B")text = text.replace("%2B","+");
    if(text.charAt(i+2) == "C")text = text.replace("%2C",",");
    if(text.charAt(i+2) == "F")text = text.replace("%2F","/");
    }
    if(text.charAt(i+1) == "3"){
    if(text.charAt(i+2) == "F")text = text.replace("%3F","?");
    if(text.charAt(i+2) == "B")text = text.replace("%3B",";");
    if(text.charAt(i+2) == "D")text = text.replace("%3D","=");
    if(text.charAt(i+2) == "A")text = text.replace("%3A",":");
    }
    if(text.charAt(i+1) == "4"){
    if(text.charAt(i+2) == "0")text = text.replace("%40","@");
    }
    }
    }
    return text;
    }
      

  4.   

    var URL={
        encode:function(text) {
            var schars="!\"#$%&'()*+,/:;<=>?[]^`{|}~%",res=[],i=0,ch,c;
            for(;i < text.length;i++) {
                ch=text.charAt(i);
                c=text.charCodeAt(i);
                if(c >0x7E )
                    res[i]=encodeURI(ch);
                else {
                    if(ch===" ")
                        res[i]="+"
                    else if(schars.indexOf(ch)===-1)
                        res[i]=ch;
                    else
                        res[i]="%"+c.toString(16)
                }
            }
            return res.join("");
        },
        decode:function(text){
            var res=[],i=0,ch,asc;           
            for(var i=0;i<text.length;i++){              
                ch= text.charAt(i);              
                if(ch == "+"){                   
                    res.push(" ");              
                }else if(ch=="%"){                   
                    asc = text.substring(i+1,i+3);                   
                    if(parseInt("0x"+asc)>0x7f){                       
                        res.push(decodeURI("%"+asc.toString()+text.substring(i+3,i+9).toString()) )                      
                        i+=8;                   
                    }else{                       
                        res.push(String.fromCharCode(parseInt("0x"+asc)));                       
                        i+=2;                   
                    }              
                }else{                   
                    res.push( ch);              
                }          
            }          
            return res.join("");     
        }
    };
      

  5.   

    首先看在要现在后台用相关函数转码,然后再在js这面解码(还是相关函数,c#不太了解,你baidu下),至于像'/'这样的就在js里替换