Percent encoding javascript

爷,独闯天下 提交于 2019-12-03 00:01:49

Try encodeURIComponent() or escape()

encodeURI, encodeURIComponent or escape will work the same way for your string, but they differ in details.

encodeURI is just for escaping URLs
encodeURIComponent also escapes = and &
escape works differently with non-ASCII unicode symbols

encodeURI("Ω") === encodeURIComponent("Ω") === "%CE%A9"
escape("Ω") === "%u03A9"

if you need to send a string as part of request, use encodeURIComponent

Yes, here is

escape('This Guy');

Try this encodeURIComponent()

var stringToDecode = "J&K";

var encodedString = encodeURIComponent(stringToDecode );

Use decodeURIComponent() to decode it again when needed

More Info here

https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!