将表格行ID提交到以下页面

时间:2018-02-02 09:43:46

标签: javascript ajax html-table http-post footable

我有一个功能正常的表,我必须在其中获取row-ID以提交到下一页,其中显示了表行的详细数据。 ID由mySQL记录的ID表示。

实际结果是ID未通过Ajax / POST提交到以下页面。实际输出:

  • POST变量在以下页面为空
  • method =“post”是为整个HTML-body
  • 全局定义的
  • 在表格行上双击后,重定向到以下页面

表页面(thispage.php):

  <table class="table" id="showcase-example-1" data-toggle-column="last" data-paging="true" data-paging-size="15" data-filtering="true" data-sorting="true" data-state="true" data-empty="no records yet">
    <thead>
        <tr>
            <th data-breakpoints="xs" data-sorted="true">Account Name 1</th>
            <th data-breakpoints="xs sm md">Account Name 2</th>
            <th data-breakpoints="xs">Address 1</th>
            <th data-breakpoints="xs">Address 2</th>  
            <th data-breakpoints="xs">ZIP</th>
            <th data-breakpoints="xs">City</th>
            <th data-breakpoints="xs sm md">State</th>
            <th data-breakpoints="xs sm">Country</th>
            <th data-breakpoints="xs sm">Internet</th>
            <th data-breakpoints="xs sm md">Telephone Fixed Line</th>
            <th data-breakpoints="xs sm md">Line of Business</th>
            <th data-breakpoints="xs sm md">Turnover</th>
            <th data-breakpoints="xs sm md">Number Employees</th>
            <th data-breakpoints="xs sm md">Number Subsidaries</th>
            <th data-breakpoints="xs sm md">Our Competition</th>
        </tr>
    </thead>
    <tbody action="thispage.php">
                    <tr data-expanded="true" type="text" name="recordIDaccounts" class="recordIDaccounts" value="12" ondblclick="window.location.replace('nextpage.php')">
            <td>ABC</td>
            <td>Inc.</td>
            <td>Examplestreet</td>
            <td>No. 1</td>
            <td>12345</td>
            <td>Examplecity</td>
            <td>Examplestate</td>
            <td>Examplecountry</td>
            <td>www.internet.com</td>
            <td style="min-width:180px;">+1-123-1234567</td>
            <td>Machinery</td>
            <td>1 Mio.</td>
            <td>123</td>
            <td>12</td>
            <td>Examplecompetition</td>
        </tr>
                </tbody>
</table>

<script type="text/javascript">

//dynamische Tabelle
jQuery(function($){
    $('.table').footable();
});

//Account-ID des doppelgeklickten Datensatzes auf die Folgeseite übergeben
$('.recordIDaccounts').on('dblclick', 'tr', function(e){
    e.preventDefault();
    var row = FooTable.getRow(this);
    var value = row.val(); //liefert ein multidimensionales Array mit allen Zeilen-Daten
    var id = this.cells[2].innerHTML; //die ID befindet sich an 3. Position
    var recordIDaccounts = id.toString();
    console.log(recordIDaccounts);
    $.ajax({
        method: "POST", //as well as type: "POST",
        url: "accountsdetails.php",
        data: {recordIDaccounts: recordIDaccounts}        //wenn die Änderung ausgeführt wurde    
    }).done(function(msg){
        //alert("recordIDaccounts übermittelt"); 
    });
});
</script>

这里是POST变量保持为空的接收页面:

<?PHP
//Datensatz-ID des übergebenen Accounts ermitteln
    if(array_key_exists("recordIDaccounts", $_POST)){
        $recordIDaccounts = mysqli_real_escape_string($link, $_POST['recordIDaccounts']);
    }

echo "Post-ID Datensatz-Nummer -recordIDaccounts-: ".$recordIDaccounts."<br>";
?>

你有什么想法吗?我正在使用ajax工作很多,但现在第一次提交表行ID ...

1 个答案:

答案 0 :(得分:0)

你正在使用我找不到的表插件&#34; get&#34;文档。

如果这样可行,你可以ajax数组的内容:

$('.recordIDaccounts').on('dblclick', function() {
  var vals = [];
  $("td", this).each(function() {
    vals.push($(this).text());
  });
  console.log(vals)
  // here you have an array of the textual content of the cells
});