I'm using the post method to submit a form to another HTML file I specified with action = " ", but once it redirects me to my second HTML file how can I display the data it received? Using JavaScript.
Asked
Active
Viewed 37 times
1
-
Possible duplicate of [How to read the post request parameters using javascript](https://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript) – caramba Oct 05 '17 at 05:54
-
Do the HTML documents have the same origin? – guest271314 Oct 05 '17 at 06:03
3 Answers
0
Setup a node.js server and read the values that have been posted. HTML itself does not receive data per se, but you can generate HTML server side with what you read.

Walle Cyril
- 3,087
- 4
- 23
- 55
0
It looks like nearly impossible to read POST from client-side [javascript]
Have a look at this : how to read the post request parameters using javascript!

Nikhil Biju
- 26
- 3
0
You can make a GET
request and parse the query string parameters at requested HTML document
.
HTML
<form action="post.html" method="GET">
<input name="a" value="1" />
<input name="file" type="file"/>
<input type="submit" />
</form>
JavaScript at HTML document where <form>
is submitted
const form = document.forms[0];
form.onsubmit = e => {
e.preventDefault();
// convert `File` object to `data URI`
if (form.file.files.length) {
console.log(form.file.files);
const reader = new FileReader;
reader.onload = () => {
form.file.type = "text";
form.file.value = reader.result;
form.submit()
}
reader.readAsDataURL(form.file.files[0]);
}
}
at HTML document requested by <form>
GET
request
// get query string parameters as array of key, value pairs
// do stuff with form data
const formData = [...new URLSearchParams(location.search).entries()];

guest271314
- 1
- 15
- 104
- 177