[英]encodeURIComponent() adds too many characters
Either my encodeURICOmponent() in java script is adding to many characters or I don't understand exactly how it works. 我的java脚本中的encodeURICOmponent()正在添加到许多字符中,或者我不完全了解它的工作方式。
I am using this line of code: 我正在使用以下代码行:
var encoded = encodeURIComponent(searchTerm);
When I look in the chrome inspect element after passing Abt 12
it shows the encoded variable added to the URL as this: 当我通过Abt 12
后查看chrome inspect元素时,它显示了将编码后的变量添加到URL中,如下所示:
Abt%252012
I would think it should be this: 我认为应该是这样的:
Abt%12
So when I pass it through PHP I get really odd results when actually conducting the search. 因此,当我通过PHP传递它时,在实际执行搜索时会得到非常奇怪的结果。
形成注释后,看起来好像是通过jQuery ajax请求将值发送到服务器,然后它将处理参数编码,因此无需再次对其进行编码。
$.get("website.php", { p: searchTerm, })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.