查询字符串中Hash(#)的行为是什么 [英] What is the behavior of Hash(#) in query string
问题描述
我正在发送以下带有查询字符串的网址.在查询字符串中一个参数 "approverCmt"具有带哈希值(#)的值.
I am sending the below url with query string. In the query string one parameter "approverCmt" has value with hash(#).
"/abc/efd/xyz.jas?approverCmt=Transaction Log #459505&batchNm=XS_10APR2015_082224&mfrNm=Timberland"
在服务器端,当我尝试从收到的请求中检索它时
In server side when I tried to retrieve it from the request I get
approverCmt = Transaction Log -----> "#459505" is missing
batchNm = null
mfrNm = null
如果我从查询字符串中删除哈希(#),或者如果我将%23替换为#,那么一切都会很好
And If I remove hash(#) from query string or If I replace # with %23 every thing works fine
我不明白,如果另一个参数包含一个哈希(#)符号,为什么一个参数却为null.
I don't understand why I am getting null for one parameter if another parameter contains a hash(#) symbol.
不胜感激.
推荐答案
这称为片段标识符".
如维基百科中所述:
由井号#引起的
fragment identifier
是文档URL
的可选最后部分.通常用于标识该文档的一部分.
The
fragment identifier
introduced by a hash mark # is the optional last part of aURL
for a document. It is typically used to identify a portion of that document.
#
之后的部分是client
的信息.它不会发送到服务器.将仅浏览器所需的所有内容都放在这里.
The part after the #
is info for the client
. It is not sent to the server. Put everything only the browser needs here.
您可以在JavaScript中使用encodeURIComponent()
函数对URL中的特殊字符进行编码,以便将#
字符转换为其他字符,从而可以确保将整个URL发送到服务器.
You can use the encodeURIComponent()
function in JavaScript to encode special characters in a URL, so that #
characters are converted to other characters that way you can be sure your whole URL will be sent to the server.
这篇关于查询字符串中Hash(#)的行为是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!