`
leonzhx
  • 浏览: 793393 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Difference of encode, encodeURI and encodeURIComponent

    博客分类:
  • Web
阅读更多

When to use which?

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 and the fact that this function fails to handle non-ASCII characters correctly, you should avoid use of escape() whenever possible . The best alternative is usually encodeURIComponent() .

escape() will not encode: @*/+

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 .

encodeURI() will not encode: ~!@#$&*()=:/,;?+'

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 .

encodeURIComponent() will not encode: ~!*()'

分享到:
评论

相关推荐

    JS中三种编码方式(escape,encodeURI,encodeURIComponent)

    常见的三种编码方法是`escape`、`encodeURI`和`encodeURIComponent`。这些函数各有其特定的用途,理解和掌握它们的区别对于编写健壮的JavaScript代码至关重要。 1. `escape` 函数: `escape`方法主要用于对字符串...

    简单明了区分escape、encodeURI和encodeURIComponent

    本文主要关注三个与URL编码相关的函数:`escape`、`encodeURI`和`encodeURIComponent`。这些函数各有其特定的用途,理解它们的区别至关重要。 首先,我们来看`escape`函数。`escape`并不专门用于URL编码,它实际上...

    javascript encodeURI和encodeURIComponent的比较

    背景 encodeURI 和 encodeURIComponent都是ECMA-262标准中定义的函数,所有兼容这个标准的语言(如JavaScript, ActionScript)都会实现这两个函数。它们都是用来对URI (RFC-2396)字符串进行编码的全局函数,但是...

    js中编码函数:escape,encodeURI与encodeURIComponent详解

    其它情况下escape,encodeURI,encodeURIComponent编码结果相同。  escape对0-255以外的unicode值进行编码时输出%u****格式  可以使用 unescape() 对 escape() 编码的字符串进行解码。  ECMAScript v3 反对使用该...

    ZzJavaScript encode and escape functions

    JavaScript中的编码和转义函数主要有encodeURI、encodeURIComponent和escape这三个函数,它们用于处理URL和URI中的特殊字符。下面将详细介绍这三个函数的功能和使用场景。 首先,encodeURI函数的主要用途是编码整个...

    谈谈encodeURI和encodeURIComponent以及escape的区别与应用

    本文将深入探讨`encodeURI()`、`encodeURIComponent()`以及`escape()`这三个函数的区别和应用场景。 `encodeURI()`函数主要用于对整个URI(统一资源标识符)进行编码。它不会编码URI中的保留字符,包括`!`, `#`, `$...

    JavaScript encodeURI 和encodeURIComponent

    encodeURI和encodeURIComponet函数都是javascript中用来对URI进行编码,将相关参数转换成UTF-8... encodeURIComponent:不会进行编码的字符有71个:!, ‘,(,),*,-,.,_,~,0-9,a-z,A-Z 问题:  ajax.get ( u

    javascript 字符 Escape,encodeURI,encodeURIComponent

    不会被此方法编码的字符: @ * / + encodeURI() 方法: 把URI字符串采用UTF-8编码格式转化成escape格式的字符串。 不会被此方法编码的字符:! @ # $& * ( ) = : / ; ? + ‘ encodeURIComponent() 方法: 把 URI字符...

    escape、encodeURI 和 encodeURIComponent 的区别

    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...

    深入分析escape()、encodeURI()、encodeURIComponent()的区别及示例

    JavaScript中有三个可以对字符串编码的函数,分别是: escape,encodeURI,encodeURIComponent,相应3个解码函数:unescape, decodeURI, decodeURIComponent 。 下面简单介绍一下它们的区别: 1 escape()函数 定义和...

    escape、encodeURI、encodeURIComponent等方法的区别比较

    escape 方法返回一个可在所有计算机上读取的编码 String 对象。function escape(charString : String) : String参数charString 必选。要编码的任何 String 对象或文本。 备注escape 方法返回一个包含 charstring ...

    JS的encodeURI和java的URLDecoder.decode使用介绍

    如果不想在url中看到有明文,比如http://localhost:8080/template_1/login.action?user=张三 可以使用js的encodeURI的URLDecoder.decode一起使用一起来把url加密下 (1)JS在页面上把数据var val = encodeURI...

    Video Encode and Decode GPU Support Matrix.xlsx

    Video Encode and Decode GPU Support Matrix.xlsx

    HDB3 ENCODE AND DECODE

    HDB3 ENCODE AND DECODE,详细设计与实现,参考一下下啊

    DVI encode and decode source code for FPGA

    DVI 1.0 encode and decode source code, write with verilog, with simulation project, synplify project and all soure code. They're have been running on xilinx spartan3A FPGA. Can be used in real project...

    URL编码转换,escape() encodeURI() encodeURIComponent()

    不会被此方法编码的字符: @ * / +英文解释:MSDN JScript Reference: The escape method returns a string value (in Unicode format) that contains the contents of [the argument]....

    Turbo encode and decode

    Turbo编码和解码是无线通信领域中的关键技术,特别是在LTE(Long Term Evolution)系统中,它对数据传输的高效性和可靠性起着至关重要的作用。本文将深入探讨Turbo编码的工作原理、编码过程、解码策略以及在LTE系统...

    只需zint.h和zint.lib库,无需动态链接库,即可使用

    ZBarcode_Encode_and_Buffer(my_symbol, (unsigned char *)m_keyString.toUtf8().data(), 0, 0); QPixmap pixmap = Bitmap2Pixmap((unsigned char *)my_symbol->bitmap, my_symbol->bitmap_width, my_symbol->bitmap...

Global site tag (gtag.js) - Google Analytics