Javascript 表单数据和请求有效负载之间有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10494574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between form data and request payload?
提问by Amogh Talpallikar
When I send an AJAX Post request and send parameters in queryString in send() method,
当我在 send() 方法中发送 AJAX Post 请求并在 queryString 中发送参数时,
Chrome Developer Tool's XHR capture tool shows the parameters under request payload. and when I use jquery's post function, The tool shows parameters under Form Data section.
Chrome 开发者工具的 XHR 捕获工具显示了请求负载下的参数。当我使用 jquery 的 post 函数时,该工具会在“表单数据”部分下显示参数。
What is the difference ?
有什么不同 ?
采纳答案by jJ'
you have not provided enough information how you use the send function, but I assume that you do not set mime type to specify you are sending form data
您没有提供足够的信息如何使用发送功能,但我假设您没有设置 mime 类型来指定您正在发送表单数据
xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
the data sent are in this case encoded as you encode a query string
在这种情况下,发送的数据在编码查询字符串时进行编码
xhr.send("name=foo&value=bar");
otherwise it will not be interpreted as form data by Developer Tools.
否则它不会被开发者工具解释为表单数据。
jquery does majority of work for you in this regard.
jquery 在这方面为您做了大部分工作。
Update:To answer explicitly what is the difference...
更新:明确回答有什么区别......
if a request (typically POST) has
Content-type
header set toapplication/x-www-form-urlencoded
the body is expected to be in the form of a standard querystring with url-encoded key=
valuepairs joined by&
. Form datasection then shows the key-value parameters (when viewed parsed). This way was much more common in past because it is a default for HTML forms.other cases are shown in Request payloadsection (and nowadays parsed for readability as well for common formats like JSON).
如果请求(典型地POST)具有
Content-type
标头集合至application/x-www-form-urlencoded
所述主体预计为与网址编码标准查询字符串的形式键=
值通过加入对&
。表单数据部分然后显示键值参数(当查看解析时)。这种方式在过去更为常见,因为它是 HTML 表单的默认设置。其他情况显示在请求有效负载部分(现在解析为可读性以及常见格式,如 JSON)。