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 pom文件依赖管理,未找到依赖
    • ¥15 现在后端返回给我一堆下载地址,都是一个视频切片后的,如何在uniapp安卓环境下将这些分片的视频下周并且合并成原始视频并下载到本地。
    • ¥15 Unity导出2D项目运行时图片变成马赛克
    • ¥15 关于communitytoolkit.mvvm的生成器得到的代码看起来没有被使用的问题
    • ¥15 matlab中此类型的变量不支持使用点进行索引
    • ¥15 咨询第六届工业互联网数据创新大赛原始数据
    • ¥15 Pycharm无法自动补全,识别第三方库函数接收的参数!
    • ¥15 STM32U575 pwm和DMA输出的波形少一段
    • ¥30 android百度地图SDK海量点显示标题
    • ¥15 windows导入environment.yml运行conda env create -f environment_win.yml命令报错