简体   繁体   English

如何在提交表单的HTML文件中显示使用post方法提交的值?

[英]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.

相关问题 如何使用C#从HTML网页提交的POST表单中下载PDF? - How do I download a PDF from an HTML webpage-submitted POST form using C#? 提交表单后如何调用方法? - How do I call a method when a form is submitted? html, javascript - 每次使用 Post 方法提交表单时打开一个新选项卡 - html, javascript - open a new tab every time a form gets submitted using Post method 提交表单后,复选框会打开onClick链接,但是如何同时发布表单? - The Checkbox opens link onClick when form is submitted, but how do I post the form at the same time? 提交表单发布表单后,如果只能通过发布访问文件,如何将消息发送到html / javascript? 发布请求 - After form post form is submitted, how to send message to html/javascript if file can only be accessed through post? post request 如何检索提交回 UI 的动态响应式表单值? - How to retrieve the dynamic reactive form values which is submitted back to UI? 在提交表单之前,如何检查HTML中的表单元素? - How do I check form elements in HTML before the form has been submitted? 显示提交的值 - displaying the submitted values 找出提交的HTML表单 - Find out which html form was submitted 提交表单后,如何将表单结果发布到另一个URL? - How do I POST my form results to another URL after it's been submitted?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM