简体   繁体   English

将 html 表发送到 php

[英]Send a html table to php

I create a table in a form but this is the only thing is not fetched.我在表单中创建了一个表,但这是唯一未获取的内容。

Used bootstable to create this table.使用bootstable创建此表。

The Table and some button controls of the cells making them editable and can add or delete row:表格和单元格的一些按钮控件使它们可编辑并且可以添加或删除行:

<table class="table table-bordered table-striped table-hover table-condensed  text-center" id="DyanmicTable" name="DyanmicTable">
    <thead>
        <tr>
            <th class="text-center">Repère</th>
            <th class="text-center">Quantité</th>
            <th class="text-center">Segments</th>
      <th class="text-center">Fixations latérales</th>
      <th class="text-center">Dalle à gauche</th>
      <th class="text-center">Commentaires</th>
            <th class="text-center">
        <button id="addNewRow" class="waves-effect waves-light btn">Ajouter une ligne</button>

            </th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
        </tr>
    </tbody>
</table>

The script used to fetch the form and send it to PHP:用于获取表单并将其发送到 PHP 的脚本:

<script>
  const myForm = document.getElementById('msform');

  myForm.addEventListener('submit', function (e) {
    e.preventDefault();

    var formData = new FormData(this);

    fetch('test.php',{
      method: 'post',
      body: formData,
    }).then(function (response) {
      return response.text();
    }).then(function(text){
      console.log(text);
    }).catch(function(error) {
      console.log(error);
    });
  });

</script>

我建议在你的 PHP 代码中使用这个函数而不捕捉错误

<? include('table.html') ; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM