日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > web前端 > jscript > javaScript中URL編碼轉換,escape() encodeURI() encodeURIC

javaScript中URL編碼轉換,escape() encodeURI() encodeURIC

來源:程序員人生   發布時間:2014-04-09 05:57:02 閱讀次數:3170次
  建站學院文檔 在使用url進行參數傳遞時,經常會傳遞一些中文名的參數或URL地址,在后臺處理時會發生轉換錯誤。在有些傳遞頁面使用GB2312,而在接收頁面使用UTF8,這樣接收到的參數就可能會與原來發生不一致。使用服務器端的urlEncode函數編碼的URL,與使用客戶端javascript的 encodeURI函數編碼的URL,結果就不一樣。
  javaScript中的編碼方法:
  escape() 方法:
  采用ISO Latin字符集對指定的字符串進行編碼。所有的空格符、標點符號、特殊字符以及其他非ASCII字符都將被轉化成%xx格式的字符編碼(xx等于該字符在字符集表里面的編碼的16進制數字)。比如,空格符對應的編碼是%20。unescape方法與此相反。不會被此方法編碼的字符: @ * / +

  英文解釋:MSDN JScript Reference: The escape method returns a string value (in Unicode format) that contains the contents of [the argument]. All spaces, punctuation, accented characters, and any other non-ASCII characters are replaced with %xx encoding, where xx is equivalent to the hexadecimal number representing the character. For example, a space is returned as "%20."
Edge Core Javascript Guide: The escape and unescape functions let you encode and decode strings. The escape function returns the hexadecimal encoding of an argument in the ISO Latin character set. The unescape function returns the ASCII string for the specified hexadecimal encoding value.

  encodeURI() 方法:把URI字符串采用UTF-8編碼格式轉化成escape格式的字符串。不會被此方法編碼的字符:! @ # $& * ( ) = : / ; ? + '

  英文解釋:MSDN JScript Reference: The encodeURI method returns an encoded URI. If you pass the result to decodeURI, the original string is returned. The encodeURI method does not encode the following characters: ":", "/", ";", and "?". Use encodeURIComponent to encode these characters. Edge Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character

  encodeURIComponent() 方法:把URI字符串采用UTF-8編碼格式轉化成escape格式的字符串。與encodeURI()相比,這個方法將對更多的字符進行編碼,比如 / 等字符。所以如果字符串里面包含了URI的幾個部分的話,不能用這個方法來進行編碼,否則 / 字符被編碼之后URL將顯示錯誤。不會被此方法編碼的字符:! * ( )

  英文解釋:MSDN JScript Reference: The encodeURIComponent method returns an encoded URI. If you pass the result to decodeURIComponent, the original string is returned. Because the encodeURIComponent method encodes all characters, be careful if the string represents a path such as /folder1/folder2/default.html. The slash characters will be encoded and will not be valid if sent as a request to a web server. Use the encodeURI method if the string contains more than a single URI component. Mozilla Developer Core Javascript Guide: Encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, or three escape sequences representing the UTF-8 encoding of the character.

  因此,對于中文字符串來說,如果不希望把字符串編碼格式轉化成UTF-8格式的(比如原頁面和目標頁面的charset是一致的時候),只需要使用 escape。如果你的頁面是GB2312或者其他的編碼,而接受參數的頁面是UTF-8編碼的,就要采用encodeURI或者 encodeURIComponent。

        另外,encodeURI/encodeURIComponent是在javascript1.5之后引進的,escape則在javascript1.0版本就有。

  英文注釋:The escape() method does not encode the + character which is interpreted as a space on the server side as well as generated by forms with spaces in their fields. Due to this shortcoming, you should avoid use of escape() whenever possible. The best alternative is usually encodeURIComponent().Use of the encodeURI() method is a bit more specialized than escape() in that it encodes for URIs [REF] as opposed to the querystring, which is part of a URL. Use this method when you need to encode a string to be used for any resource that uses URIs and needs certain characters to remain un-encoded. Note that this method does not encode the ' character, as it is a valid character within URIs.Lastly, the encodeURIComponent() method should be used in most cases when encoding a single component of a URI. This method will encode certain chars that would normally be recognized as special chars for URIs so that many components may be included. Note that this method does not encode the ' character, as it is a valid character within URIs.
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 麻豆传媒一区二区三区 | 91精品啪在线观看国产线免费 | 国产一区二区黑人欧美xxxx | 精品一区视频 | 福利视频一区 | 爱爱视频网| 99激情网 | 精品国产不卡一区二区三区 | 国产精品视频导航 | 搞黄网站 | 亚洲一区视频在线 | 麻豆成人在线观看 | 81精品国产乱码久久久久久 | 国产极品视频 | 狠狠色伊人亚洲综合网站色 | 亚洲午夜精品 | 天天操夜夜曰 | 欧美日韩一区二区三区 | 日韩网站在线 | 免费视频一二三区 | av在线免费网站 | 亚洲免费毛片 | 美女福利在线观看 | 最新日韩精品视频 | 美女视频黄是免费 | 亚洲日本视频 | www.色婷婷 | 成人a在线| 亚洲精品国产综合99久久夜夜嗨 | 久久精品视频在线观看 | 日韩成人精品视频 | 男女在线视频 | 日韩精品视频在线 | 国产ai视频 | 国产精品久久久久免费 | 国产成人在线播放 | 国产高清一二三区 | 免费国产高清 | 91精品国产九九九久久久亚洲 | 日韩综合精品 | 国产三区四区 |