使用ajax中的post更新表

时间:2015-01-26 10:22:35

标签: jquery ajax twitter-bootstrap codeigniter

我使用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 woul是一个参数。我怎样才能抓住模态表中的字段?

3 个答案:

答案 0 :(得分:1)

您可以获取值split(),如下:

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

演示:: jsFiddle

答案 1 :(得分:0)

像这样编辑你的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 },
[...]

答案 2 :(得分:0)

您可以通过将id设置为表格列和按钮来实现:

<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)
});