第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

什么時候使用轉(zhuǎn)義代替encodeURI/encodeURIComponent?

什么時候使用轉(zhuǎn)義代替encodeURI/encodeURIComponent?

慕田峪4524236 2019-06-03 14:52:45
什么時候使用轉(zhuǎn)義代替encodeURI/encodeURIComponent?在編碼要發(fā)送到web服務器的查詢字符串時-何時使用escape()你什么時候用encodeURI()或encodeURIComponent():使用轉(zhuǎn)義:escape("% +&=");或使用encodeURI()/encodeURIComponent()encodeURI("http://www.google.com?var1=value1&var2=value2");encodeURIComponent("var1=value1&var2=value2");
查看完整描述

4 回答

?
12345678_0001

TA貢獻1802條經(jīng)驗 獲得超5個贊


encodeURIComponent不編碼-_.!~*'(),導致在XML字符串中將數(shù)據(jù)提交給php時出現(xiàn)問題。


例如:

<xml><text x="100" y="150" value="It's a value with single quote" />

</xml>


一般逃逸encodeURI

%3Cxml%3E%3Ctext%20x=%22100%22%20y=%22150%22%20value=%22It's%20a%20value%20with%20single%20quote%22%20/%3E%20%3C/xml%3E


您可以看到,單引號沒有編碼。為了解決問題,我創(chuàng)建了兩個函數(shù)來解決項目中的問題,用于編碼URL:


function encodeData(s:String):String{

    return encodeURIComponent(s).replace(/\-/g, "%2D").replace(/\_/g, "%5F").replace(/\./g, "%2E").replace(/\!/g, "%21").replace(/\~/g, "%7E").replace(/\*/g, "%2A").replace(/\'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29");

}

對于解碼URL:


function decodeData(s:String):String{

    try{

        return decodeURIComponent(s.replace(/\%2D/g, "-").replace(/\%5F/g, "_").replace(/\%2E/g, ".").replace(/\%21/g, "!").replace(/\%7E/g, "~").replace(/\%2A/g, "*").replace(/\%27/g, "'").replace(/\%28/g, "(").replace(/\%29/g, ")"));

    }catch (e:Error) {

    }

    return "";

}


查看完整回答
反對 回復 2019-06-03
?
HUWWW

TA貢獻1874條經(jīng)驗 獲得超12個贊

.之間的區(qū)別encodeURI()和encodeURIComponent()這11個字符是由encodeURIComponent編碼的,而不是由encodeURI編碼的:


https://img1.sycdn.imooc.com//5cf4c3f10001d66104830198.jpg

我很容易地生成了這個表控制臺表在GoogleChrome中使用以下代碼:


var arr = [];

for(var i=0;i<256;i++) {

  var char=String.fromCharCode(i);

  if(encodeURI(char)!==encodeURIComponent(char)) {

    arr.push({

      character:char,

      encodeURI:encodeURI(char),

      encodeURIComponent:encodeURIComponent(char)

    });

  }

}

console.table(arr);


查看完整回答
反對 回復 2019-06-03
  • 4 回答
  • 0 關(guān)注
  • 1321 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號