44
votes

When I send an AJAX Post request and send parameters in queryString in send() method,

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.

What is the difference ?

1
For future readers follow this: stackoverflow.com/questions/9597052/…Michael J. Calkins
@revo This was asked in 2012. The one you linked was asked in 2014. And you're pointing this out in 2019 😅Whatever works!Amogh Talpallikar
I'm not doing anything wrong here. Although the other question is younger, it received much more attention. Hence my vote.revo
@revo Ah I get it. No problem. I'll vote as well.Amogh Talpallikar

1 Answers

29
votes

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

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.

Update: To answer explicitly what is the difference...

  • if a request (typically POST) has Content-type header set to application/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.

  • other cases are shown in Request payload section (and nowadays parsed for readability as well for common formats like JSON).