URL Encoding—Ampersand Problem

怎甘沉沦 提交于 2019-12-08 14:26:18

问题


I'm having some trouble with some character encoding causing some problems with a search form on my website. One of the possible field values has an ampersand in it. When this is selected and a search is submitted the ampersand is encoded to: %2526

Upon using the pagination links at the bottom of the page and navigating to the second page in the list of results the ampersand is encoded to: %26

Finally...in an attempt to navigate to the 3rd page in the list the ampersand is changed back to: & This breaks the form as it assumes there's a variable that isn't actually there.

Why is the encoding changing? How can I fix this? Thanks for your help!


回答1:


It looks like the field is being encoded twice. First pass will result in & changed into %26, then urlencoding %26 will result in %2526, since the encoding for % itself is %25.




回答2:


If you want to use Andaman & Nicobar in web API.

You can use instead of & you can use %26 and whole will be written as below.

Andaman+%26+Nicobar




回答3:


I am assuming that you are navigating using links that are displayed on your web page.

The answer is in how you are generating the URL in that link's href tag. You (most likely) are not re-encoding the ampersand in the URL when you are setting that href attribute's value.



来源:https://stackoverflow.com/questions/7012810/url-encoding-ampersand-problem

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