数据表中的fnDraw不起作用

时间:2015-12-31 14:56:35

标签: php ajax twitter-bootstrap datatables datatables-1.10

我正在使用数据表1.10.10和数据表的bootstrap样式。我有2个PHP文件,一个是driver-list.phpdriver-edit.php。但driver-edit.php只编码模态窗口。当我单击编辑按钮时,它会将ID传递给driver-edit.php。它会在driver-list.php中打开一个模态窗口。但是当我单击driver-edit.php的提交按钮时,单击提交按钮后它不会更新。

我尝试了fnDraw()fnReloadAjax(), ajax.reload()个功能。但它总是失败。

驾驶员list.php的

<div class="container">
    <div class="well">
        <div class="col-lg-3"><label class="control-form">Driver-List</label></div>

        <div class="col-lg-offset-11"><button type="submit" class="btn btn-primary">Add New</button></div>

    </div>

    <div class="table-responsive">
    <table class="table table-hover myTable" id="data-table">
        <thead>
            <tr>
                <th>No</th>
                <th>First name</th>
                <th>Last Name</th>                   
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <?php
                include 'inc/connection.php';

                $que="SELECT * FROM driver";
                $query_run=mysqli_query($con,$que);
                $no=1;

                while($row=mysqli_fetch_array($query_run))
                {               
            ?>
                <tr>
                    <td><?php echo $no++; ?></td>
                    <td><?php echo $row['first_name']; ?></td>
                    <td><?php echo $row['last_name']; ?></td>
                    <td><div class="btn-group"><a class='Edit btn btn-primary' onclick="javascript: editaxa('<?php echo $row['driver_id'];?>');" data-toggle="modal" href="#form_modal" data-target="#myModal" data-Id="<?php echo $row['driver_id'];?>">Edit</a></div>
    </td>                        

                </tr>
            <?php
                }
                mysqli_close($con);
            ?>
        </tbody>
    </table>
    </div>
</div>


<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

        </div>
    </div>
</div>



 <script>
$(document).ready(function() {
     var dt=$('#driver-list').DataTable();
} );
function editaxa(xx){

    var Id_Edit=xx;

    $.ajax({
        url:"views/driver/driver-edit.php?Id="+Id_Edit,
        cache:false,
        success:function(result){
            $(".modal-content").html(result);

    }});
}   

</script>

驾驶员edit.php

<?php
$id=$_GET['Id'];

include '../../inc/connection.php';

$query="SELECT * FROM driver WHERE driver_id='$id'";
$query_run=mysqli_query($con,$query);
$row=mysqli_fetch_array($query_run);

?>


<div class="modal-body">


    <form class="form-horizontal" role="form" action="" method="POST" enctype="multipart/form-data">
        <div class="form-group">
            <div class="row">
                <div class="col-xs-offset-1 col-lg-2">                                                
                    <label class="control-label">First Name</label>                            
                </div>

                <div class="col-lg-3">
                    <div class="input-group">                                
                        <input type="text"  id="first_name" class="form-control"  name="first_name" requi red="requi red" autocomplete="off" value="<?php echo $row['first_name']; ?>" />
                        <span class="input-group-addon"><i class="" id="a"></i></span> 
                    </div>
                </div>


                <div class="col-lg-2">
                    <label class="control-label">Last Name</label>
                </div>


                <div class="col-lg-3">
                    <div class="input-group">   
                        <input type="text"  id="last_name" class="form-control"  name="last_name"  requi red="requi red" autocomplete="off" value="<?php echo $row['last_name']; ?>"/>
                        <span class="input-group-addon"><i class=""></i></span> 
                    </div>
                </div>
                <br />
            </div>
        </div>


        <div class="modal-footer">

            <div class="form-group">
                <div class="row">
                    <div class="col-xs-offset-3 col-lg-2">
                        <button class="btn btn-success-outline btn-block" id="submit" type="submit">Submit</button>
                    </div>
                 </div>
            </div> 
        </div>
    </form>
</div>


<script>
$(document).ready(function(e) { 
    formData =new FormData(this)
        $.ajax({
            url: "actions/driver/driver-edit.php",
            type: "POST",
            data: formData,
            contentType: false,
            cache: false,
            processData:false,
            success: function(data)
            {
                    $('#myModal').modal('hide');                       
                    dt.fnDraw();     // dt is defined in driver-list.php
            },
            error: function(data) 
            {
                alert(console.log(data))
            }
       });
        }
    }));


});




</script>

0 个答案:

没有答案