javascript - 使用非 UTF-8 编码的 get 方法提交表单

标签 javascript html utf-8 uri

  1. 我有一个page采用非 UTF-8 编码。
  2. 有一个带有 method="get" 的表单。如果我提交这些非 UTF-8 字符,它们就会到达 URI。
  3. 当我尝试运行 decodeURIComponent() 时在 URI 上,我得到 infamous error :URIError: malformed URI sequence .

请关注the testcase

问题:

  1. 上述哪一个步骤(1、2、3)有问题? 1 应该没问题。 2是标准提交方式<form> 。 3是标准函数。所有这些都是标准的!但一定有什么地方出错了。

  2. URI 中是否允许使用 UTF-8 以外的编码字符? (如果不是,问题显然出在步骤 2)。

  3. 正确诊断问题后,问题是 - 什么是干净的解决方案?页面必须采用非 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/

相关文章:

javascript - Ember 2.16 组件集成测试模拟操作的返回 promise

javascript - 如何解决 Eloquent Javascript "Chess Board"?

Javascript onclick 改变多个元素的颜色

html - 如何将 CSS/HTML 搜索框用于 Google 协作平台中带有 Apps 脚本的链接部分?

html - 按钮对齐文本下方的背景图像

javascript - 为什么浏览器不想将文本放置在 <tr> 标记之间?

c++ - 使用哪个,utf8 还是 Ascii

javascript - .load() 不适用于 ul li click

java - “UTF-8” 编码在 java 构建中不起作用

javascript - JS中带有UTF8字符的正则表达式自动换行