weixin_33713503 2016-06-25 17:55 采纳率: 0%
浏览 4

AJAX JQuery删除数据

Help, I have a big problem with ajax, I deleted records using ajax, using confirmation window bootstrap, very well when I press the button to delete it runs correctly and the table refreshes without any problem, the problem is that when I want to remove another record, opens the modal window bootstrap, but do not run anything

        <script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
        <script data-require="jquery@*" data-semver="2.0.3" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
        <script data-require="bootstrap@*" data-semver="3.1.1" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
        <link data-require="bootstrap-css@3.1.1" data-semver="3.1.1" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" />
            <!--<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>-->
    <script type="text/javascript" >
        var base_url = '<?php echo base_url() ?>clientes/eliminar';
            $('#confirmar').click(function (e) {
                var modalDiv = $(e.delegateTarget);
                var id = $(this).data('recordId');
                setTimeout(function () {
                }, 100000);
                    type: "POST",
                    url: base_url,
                    data: "idcliente=" + id,
                    beforeSend: function () {
                    success: function (respuesta) {


            // Bind to modal opening to set necessary data properties to be used to make request
            $('#confirm-delete').on('show.bs.modal', function (e) {

                var data = $(e.relatedTarget).data();
                $('.title', this).text(data.recordTitle);
                $('.btn-ok', this).data('recordId', data.recordId);

        .modal.loading .modal-content:before {
            content: 'Loading...';
            text-align: center;
            line-height: 155px;
            font-size: 20px;
            background: rgba(0, 0, 0, .8);
            position: absolute;
            top: 55px;
            bottom: 0;
            left: 0;
            right: 0;
            color: #EEE;
            z-index: 1000;
    <li><a data-toggle="modal" data-target="#events-modal">Nuevo Cliente</a></li>
<div id="contenedor2" class="col-md-8 col-md-offset-2">
    <table >
            <th class="col-xs-4" style="text-align:left;border:1px solid">Name</th>
            <th class="col-xs-4" style="text-align:left;border:1px solid">tel</th>
            <th class="col-xs-2" style="text-align:center;border:1px solid">Email</th>
            <th class="col-xs-1" style="text-align:center;border:1px solid">Edit</th>
            <th class="col-xs-1" style="text-align:center;border:1px solid">Delete</th>
        <tbody class="tablenotas">
            if (is_null($lista)) {
                echo "<h4>Para comenzar presiona el bot&oacute;n Nuevo</h4>";
            } else {
                $base = base_url();
                foreach ($lista as $fila):
                    echo '<tr style="text-align:justify">' .
                    '<td style="text-align:left;border:1px solid">' . $fila->NombreCliente . '</td>' .
                    '<td style="text-align:left;border:1px solid">' . $fila->RazonSocial . '</td>' .
                    '<td style="text-align:center;border:1px solid">' . $fila->Email . '</td>' .
                    '<td style="text-align:center;border:1px solid"><a  href="' . $base . 'clientes/detalles_cliente/' . $fila->Id_Cliente . '"><span class="glyphicon glyphicon-edit"></span></a></td>' .
                    '<td style="text-align:center;border:1px solid"><a href="#" data-record-id="' . $fila->Id_Cliente . '"  data-toggle="modal" data-target="#confirm-delete"><span class="glyphicon glyphicon-trash"></span></td>' .
    <div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel">Confirm Delete</h4>
                <div class="modal-body">
                    <p>Estás a punto de eliminar <b><i class="title"></i></b> el registro, este procedimiento es irreversible.</p>
                    <p>Desea proceder?</p>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                    <button type="button" id="confirmar" class="btn btn-danger btn-ok">Continuar</button>

in my controller

function delete() {
    $idcliente = $this->input->post('idcliente');
    if ($this->ion_auth->is_admin()) {
        if ($this->Cliente_model->delete($idcliente)) {
            $this->_data['lista'] = $this->Cliente_model->getClientes();
            $this->load->view('user/clientes', $this->_data);
  • 写回答

1条回答 默认 最新

  • lrony* 2016-06-25 19:05

    It look like that the modal html is inside the DIV with id #contenedor2 so when you change the HTML ($('#contenedor2').html(respuesta);) you also add a new DIV with the modal HTML, BUT this will not work after that:

    $('#confirmar').click(function (e) {
        // YOUR CODE

    To fix it, try delegating the event like this (replace the above code with the following):

    $('#contenedor2').on('click', '#confirmar', function (e) {
        var modalDiv = $(e.delegateTarget);
        var id = $(this).data('recordId');
        ..... REST OF YOUR CODE



  • ¥15 c#直接使用C++ 写的class 后续
  • ¥15 为何显示keyerror fruit
  • ¥15 关于#stm32#的问题:/* User can add his own implementation to report the HAL error return state */
  • ¥15 imageware粗糙度表面
  • ¥15 python使用pulp线性优化时报错
  • ¥15 为什么我的uibot导入py模块出错呀。py文件放在了uibot里对应的python文件夹了,卸了重安也不行
  • ¥15 开源或低价数据中台哪个最好
  • ¥15 arduino编程出现字符串疑似覆盖现象
  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?
  • ¥30 STK matlab python仿真