URL encode sees “&” (ampersand) as “&” HTML entity

后端 未结 3 1385
迷失自我
迷失自我 2020-11-28 02:58

I am encoding a string that will be passed in a URL (via GET). But if I use escape, encodeURI or encodeURIComponent, &

3条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 03:22

    If you did literally this:

    encodeURIComponent('&')
    

    Then the result is %26, you can test it here. Make sure the string you are encoding is just & and not & to begin with...otherwise it is encoding correctly, which is likely the case. If you need a different result for some reason, you can do a .replace(/&/g,'&') before the encoding.

提交回复
热议问题