I was looking on how to get values of form data that are passed with POST requests and found this answer.
I know you you can get GET
query parameters quite easily in JavaScript doing window.location.search
but is there a way to do similar for POST request or document.forms
is my only option?
-
3JavaScript can't access the POST request. – Sterling Archer Apr 30 '14 at 18:01
2 Answers
To expand on what RUJordan said:
When you do a POST
, the information is sent to the server using an entirely different method and does not show up in the URL or anywhere else that JavaScript can get access to it.
The server, and only the server, can see it.
Now, it is possible to take some of the form data and fill JavaScript variables and/or hidden
form fields so the server can pass data back down to the client.
If you need more help, you'd be better off opening another question explaining exactly what problem you are trying to solve.

- 23,369
- 6
- 54
- 74
-
I'm going to try out that `hidden` approach and will open up another question if needed. Thanks. – shriek Apr 30 '14 at 18:13
Do you want javascript to see the data was POSTed to load the current page?
JavaScript does not have access to the request body (where the POST content is) that loaded the page. If you want to be able to interact with the POSTed parameters, the server that received the request would need to respond with the necessary data written back out on the page where javascript can find it. This would be done after the form was submitted, as part of the response to that POST request.
Or do you want to know what your page could POST form the forms that are on it?
Inspecting document.forms
will let you see what could be POSTed later if those forms were submitted. This would be done before the form was submitted, without a request being made.

- 178,991
- 47
- 309
- 337
-
The first one and I'm just now realizing that this is something that can only be done from server side. – shriek Apr 30 '14 at 18:07
-
@shriek Yep you need server side help then. The server needs to expose those variables explicitly to the page. How to do that depends greatly on your server side language and your goals of implementation. – Alex Wayne Apr 30 '14 at 18:09