我试图通过HTTP请求传递一个字符串,该请求具有%URL查询字符串中的一个字符.
url = url + "?q=" + str + "&block=" + block; // str contains the '%' character
Run Code Online (Sandbox Code Playgroud)
但是在我发送此信息的ColdFusion页面上返回以下错误:
元素Q在URL中未定义.
如何%在URL中对符号进行编码?
Bra*_* G. 13
您应该将您传递的所有值作为查询参数进行url编码,但是%的url编码是 %25
更新:如果您在javascript中构建查询参数,您可能希望这样做:
url=url+"?q="+encodeURIComponent(str)+"&block="+encodeURIComponent(block)
Run Code Online (Sandbox Code Playgroud)
(再次更新了ZeissS的非常有用的建议,encodeURIComponent而不是使用escape.另见http://xkr.us/articles/javascript/encode-compare/)
| 归档时间: |
|
| 查看次数: |
15185 次 |
| 最近记录: |