When I send an AJAX Post request and send parameters in queryString in send() method,
当我发送AJAX Post请求并在send()方法中以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 ?
有什么区别吗?
1 个解决方案
#1
28
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
您没有提供如何使用send函数的足够信息,但是我假设您没有设置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=
value pairs joined by&
. Form data section 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.如果一个请求(通常是POST)的内容类型头设置为application/x-www-form- urlencodes,那么主体将以标准查询字符串的形式出现,其中包含url编码的键=值对,由&连接。然后,表单数据部分显示键值参数(查看解析时)。这种方式在过去更常见,因为它是HTML表单的默认。
-
other cases are shown in Request payload section (and nowadays parsed for readability as well for common formats like JSON).
其他情况如请求有效负载部分所示(现在解析为可读性以及JSON等常见格式)。
#1
28
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
您没有提供如何使用send函数的足够信息,但是我假设您没有设置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=
value pairs joined by&
. Form data section 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.如果一个请求(通常是POST)的内容类型头设置为application/x-www-form- urlencodes,那么主体将以标准查询字符串的形式出现,其中包含url编码的键=值对,由&连接。然后,表单数据部分显示键值参数(查看解析时)。这种方式在过去更常见,因为它是HTML表单的默认。
-
other cases are shown in Request payload section (and nowadays parsed for readability as well for common formats like JSON).
其他情况如请求有效负载部分所示(现在解析为可读性以及JSON等常见格式)。