为什么我的“”是在我处理 Ajax 请求的 CGI 程序中,字符变成了空格?
我正在通过 Web 表单收集文本,并注意到当我的 Perl CGI 收集文本时,所有“+”实例都会转换为“”。我在提交之前通过 JavaScript 转义运行文本,但转义似乎保持不变。
一定有一些非常明显的东西我丢失了......我如何发送字符串“2 + 2 = 4”而不让它以“2 2 = 4”的形式到达?
I'm collecting text through a web form and noticing that when it is collected by my Perl CGI all instances of "+" are transformed into " ". I run the text through a JavaScript escape before submission, but escape seems to leave + unaltered.
There must be something really obvious that I'm missing... how do I send the string "2 + 2 = 4" through and not have it arrive as "2 2 = 4"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道你所说的使用 JavaScript 转义是什么意思。浏览器将正确编码表单字段值,CGI.pm 将正确解码它们。
例如,
我通过在输入字段中提交此表单并使用
2+2=4
获得的输出是:I do not know what you mean by using JavaScript escape. Browsers will properly encode form field values and CGI.pm will properly decode them.
For example,
The output I get from submitting this form with
2+2=4
in the entry field is:— https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Predefined_Functions /escape_and_unescape_Functions
将
escape
替换为encodeURIComponent
— https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Predefined_Functions/escape_and_unescape_Functions
Replace
escape
withencodeURIComponent
URL 中的“
+
”应编码为%2B
:将给出 a =
2 + 2 = 4
在 Javascript 中,这意味着使用
encodeURIComponent
函数:这部分代码:将给出:
注意
+
已编码。虽然这个 :
只会给出 :
请注意
+
未编码。You '
+
', in the URL, should be encoded as%2B
:Will give a =
2 + 2 = 4
In Javascript, this means using the
encodeURIComponent
function : this portion of code :will give :
Note the
+
is encoded.While this one :
would only give :
Note the
+
is not encoded.您可以将
+
编码为%2B
,如下所示:http://www.google.com/search?q=2+%2B+2You can encode
+
as%2B
, as seen in: http://www.google.com/search?q=2+%2B+2