- 我有一个page采用非 UTF-8 编码。
- 有一个带有
method="get"
的表单。如果我提交这些非 UTF-8 字符,它们就会到达 URI。 - 当我尝试运行
decodeURIComponent()
时在 URI 上,我得到 infamous error :URIError: malformed URI sequence
.
请关注the testcase 。
问题:
上述哪一个步骤(1、2、3)有问题? 1 应该没问题。 2是标准提交方式
<form>
。 3是标准函数。所有这些都是标准的!但一定有什么地方出错了。URI 中是否允许使用 UTF-8 以外的编码字符? (如果不是,问题显然出在步骤 2)。
正确诊断问题后,问题是 - 什么是干净的解决方案?页面必须采用非 UTF-8 编码。
最佳答案
火狐说:
[11:38:39.275] A form was submitted in the ISO-8859-2 encoding which cannot encode all Unicode characters, so user input may get corrupted. To avoid this problem, the page should be changed so that the form is submitted in the UTF-8 encoding either by changing the encoding of the page itself to UTF-8 or by specifying accept-charset=utf-8 on the form element. @ http://artax.karlin.mff.cuni.cz/~ttel5535/pub/bugs/form_get_submit_non_utf-8/non_utf8_uri_test.html?input=%B9
关于javascript - 使用非 UTF-8 编码的 get 方法提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19702662/