[英]How do I go about displaying the values submitted using the post method In the HTML file which the form was submitted to?
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? 我正在使用post方法将表单提交到我用action =“”指定的另一个HTML文件,但是一旦将其重定向到第二个HTML文件,如何显示收到的数据? Using JavaScript. 使用JavaScript。
Setup a node.js server and read the values that have been posted. 设置一个node.js服务器并读取已发布的值。 HTML itself does not receive data per se, but you can generate HTML server side with what you read. HTML本身本身不接收数据,但是您可以使用读取的内容生成HTML服务器端。
It looks like nearly impossible to read POST from client-side [javascript] 从客户端[javascript]读取POST似乎几乎是不可能的
Have a look at this : how to read the post request parameters using javascript ! 看看: 如何使用javascript读取发帖请求参数 !
You can make a GET
request and parse the query string parameters at requested HTML document
. 您可以发出GET
请求并在请求的HTML document
解析查询字符串参数。
HTML 的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 提交<form>
HTML文档上的JavaScript
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 在<form>
GET
请求所请求的HTML文档中
// get query string parameters as array of key, value pairs
// do stuff with form data
const formData = [...new URLSearchParams(location.search).entries()];
plnkr http://plnkr.co/edit/eP8GvUTc4xkPmuc4T8Pu?p=preview plnkr http://plnkr.co/edit/eP8GvUTc4xkPmuc4T8Pu?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.