When are you supposed to use escape instead of encodeURI / encodeURIComponent?

前端 未结 15 1181
栀梦
栀梦 2020-11-21 07:39

When encoding a query string to be sent to a web server - when do you use escape() and when do you use encodeURI() or encodeURIComponent()

15条回答
  •  星月不相逢
    2020-11-21 07:51

    I've found that experimenting with the various methods is a good sanity check even after having a good handle of what their various uses and capabilities are.

    Towards that end I have found this website extremely useful to confirm my suspicions that I am doing something appropriately. It has also proven useful for decoding an encodeURIComponent'ed string which can be rather challenging to interpret. A great bookmark to have:

    http://www.the-art-of-web.com/javascript/escape/

提交回复
热议问题