【问题标题】:Update table using post in ajax在ajax中使用post更新表
【发布时间】:2015-01-26 10:22:35
【问题描述】:

我使用 codeigniter 开发我的应用程序。我有一个从 mysql 表生成的表。这是视图:

<table class="table table-bordered table-striped table-condensed">
<thead>
    <tr>
        <th>No.  </th>
        <th>No Request</th>
        <th>Username</th>
        <th>Waktu Kirim Request</th>
        <th>Keluhan</th>                                            
        <th>Status</th>
        <th>Estimasi Penyelesaian</th>                                            
        <th>Action</th>
    </tr>
</thead>   
<tbody>
    <?php
    $no = 1;
    foreach ($data_request as $data) {
    ?>
    <tr>
        <td class="center"><?php echo $no++ . ". "; ?> </td>
        <td class="sorting1" id='no_request'><?php echo $data['kode_kantor'] . '/' . $data['kode_departement'] . '/' . date('m', strtotime($data['bulan'])) . '/' . $data['id_request']; ?> </td>
        <td class="center"><?php echo "$nama"; ?></td>
        <td class="center"><?php echo date("d-m-Y, H:i ", strtotime($data['waktu_mulai'])); ?></td>
        <td class="center"><?php echo $data['keluhan']; ?></td>                                            
        <td class="center"><a href="#" onclick="ubahStatus();"><span class="label label-important"><?php echo $data['status_request']; ?> </span></a></td> 
        <td class="center"><?php echo date("d-m-Y, H:i ", strtotime($data['waktu_tutup_request'])); ?></td>                                            
        <td  class="center">
            <a class="btn btn-info" href="#">
                <i class="halflings-icon white edit"></i>
            </a>

            <a class="btn btn-success" >
                <i class="halflings-icon white print" id="print"></i>
            </a>         
        </td>
    </tr>

    <?php } ?>
</tbody>

<div class="modal hide fade" id="myModal">

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">×</button>
    <h2>Confirm</h2>
</div>

<div class="modal-body">
    <p id="id_preview"></p>
</div>

<div class="modal-footer">
    <a href="#" id="btn-footer" class="btn btn-danger" onclick="executeStatus();">Yes</a>
    <a href="#" class="btn" data-dismiss="modal">No</a>   
</div>

这样的表:

http://jsfiddle.net/Cerlin/xammqf0u/5/embedded/result/

现在,要打印一个pdf,在[No.Request]字段中,有这样的字符串

TMS/IT/01/002, 

我只想抓住“002”,因为我的功能是这样的:

function generate_pdf($id){
    //some code here
}

002 将是一个参数。如何在模态表上抓取表格中的字段?

【问题讨论】:

    标签: jquery ajax twitter-bootstrap codeigniter


    【解决方案1】:

    你可以得到值和split()它,如:

    var idStr = $this.attr("req_id");
    var id = idStr.split("/").pop();
    alert(id); //gives 002  send it to your post
    

    演示 :: jsFiddle

    【讨论】:

      【解决方案2】:

      像这样编辑你的 html 单元格:

      <td class="sorting1" id='no_request' data-id="<?php echo $data['id_request']; ?>"><?php echo $data['kode_kantor'] . '/' . $data['kode_departement'] . '/' . date('m', strtotime($data['bulan'])) . '/' . $data['id_request']; ?> </td>
      

      在你的 javascript 中,添加一个像这样的 POST 参数:

      [...]
      data: { 'id': $(this).data().id },
      [...]
      

      【讨论】:

      • 你能在上面的javascript代码中给我更具体的例子吗?
      • 发布您的 javascript AJAX 调用,我可以向您展示如何发布这些特定数据
      • 我刚刚分叉了你的 jsfiddle :jsfiddle.net/zd4andh0 在你的打印按钮上添加了data-id="001"(当然用 $data['id_request'] 让它动态化)。并在你的javascript中添加了var id = $this.data().id; console.log(id);
      【解决方案3】:

      例如,您可以通过将 id´s 设置为表格列和按钮来做到这一点:

      <input type="button" id="button[<idFromDatabasePlacedHere>]" value="..." />
      

      还要为您的列提供相同的 id:

      <td id="column[<idFromDatabasePlacedHere>]">...</td>
      

      然后你可以像这样在 Javascript 中读取 id:

      $("input[id^='button']").click(
      function(sender)
      {
      var arSplit = $("#column" + $(this).attr("id").substring(6, $(this).attr("id").length - 1).attr("id").split("/");
      // arSplit[3] is e. g. 002 is your key to work on
      // not sure, if 6 is the character after column[ (not tested)
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 2012-08-20
        • 2017-08-04
        • 1970-01-01
        • 2016-05-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多