表格 enctype "application/json" 可用吗?

is form enctype "application/json" available?

我正在阅读此 w3c document 关于 post JSON 数据的 html 形式,并尝试对其进行测试。

我的测试形式如下:

 <form action="postjson.php" method="POST" enctype="application/json">
    <input type="hidden" name="touser" value="shenkwen" />
    <input type="hidden" name="msgtype" value="text" />
    <input type="hidden" name="agentid" value="23" />
    <input type="hidden" name="text[content]" value="test message" />
    <input type='submit' value="submit" />
  </form>

postjson.php

的内容
<?php var_dump($_POST); 

我原以为 $_POST 的值是一个 JSON 字符串,然而,它只是一个普通的 PHP 对象:

array(4) { ["touser"]=> string(8) "shenkwen" ["msgtype"]=> string(4) "text" ["agentid"]=> string(2) "23" ["text"]=> array(1) { ["content"]=> string(33) "test message" } }

我尝试删除 enctype 属性,但输出完全相同。然后我回到文档页面,注意到它说了一些表明这个标准可能没有生效的东西。

所以这也是一个关于如何使用W3C网站的问题,在我看来它的某些页面只是草稿。那么这个页面是草稿吗?当我阅读 w3c 上的页面时,我如何判断它是草稿还是工作标准?最后也是最重要的,enctype='application/json' 是否有效?

W3C 发布了许多草案和提案,然后在整个社区内进行讨论。如果草案达到通常认为有用的阶段,浏览器供应商 will/may 就会开始实施它。然后草案通常会进入 "recommendation" 阶段,这意味着 W3C 正式建议浏览器按规定实施该技术;但他们当然不能扭曲任何人的手臂来实际这样做。

每个文档都会在其顶部说明其当前状态,http://www.w3.org/TR/ 列出所有当前文档及其状态。您选择的那个在该页面上列为 "obsolete" 和 "retired",并且在其顶部有一个巨大的横幅,上面写着:

Beware. This specification is no longer in active maintenance and the HTML Working Group does not intend to maintain it further.

所以,不,目前可能没有浏览器正在实现它。

要跟踪某项功能在现实世界中的可用性,您需要查看第 3 方资源,例如 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-enctype and http://caniuse.com

仅供参考.. 有一种使用 javascript 模仿此功能的 hacky 方法。在此处查看我的图书馆:https://github.com/keithhackbarth/submitAsJSON