美文网首页
encodeURI()、encodeURIComponent()

encodeURI()、encodeURIComponent()

作者: 小代码 | 来源:发表于2018-07-05 14:48 被阅读0次

为什么要使用这些。
encodeURI():

url参数中包含空格等特殊字符,比如:
[] 中文等字符
以上字符服务器是不了解的所以需要编码。整个urI编码,包括请求参数,以及锚点,而不是hostname部分。

uri结构传输门

encodeURIComponent():

参数中包含比如auth?redirectUrl=http://www.baidu.com?x=y&y=x#30 中参数值需要进行编码才不会错认为有两个参数。
对参数值进行编码
redirectUrl=[http://www.baidu.com?x=y]
y=[x]
#30

其实是一个参数
redirectUrl=[http://www.baidu.com?x=y&y=x#30]

escape():编码处理转换,将非acii码编码为asc码。比如链接里的样例 http://tool.oschina.net/encode?type=3

https://blog.csdn.net/ma_jiang/article/details/50896048

相关文章

网友评论

      本文标题:encodeURI()、encodeURIComponent()

      本文链接:https://www.haomeiwen.com/subject/yrxpuftx.html