noty jQuery - 通知apearence

时间:2015-05-22 05:00:54

标签: javascript jquery codeigniter

我想在删除所有按钮时显示通知。我使用 noty jquery ,而我点击删除所有按钮只有按钮通知显示不完整和页面重定向我正在使用codeigniter我做的代码如下

enter image description here

// view of my file
<?php $page_url = $this->uri->segment(2);?>

<div id="contents" style="width:1024px;">

    <div class="buttons">

        <div><button class="button-choose-2 pure-button" id="delete">Delete</button></div>

        <div>
            <input type="button" class="button-choose-2 pure-button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"></div>
        <div>
            <input type="button" class="button-choose-2 pure-button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"></div>

        <div><a href="parexons_con/add_team"><button class="button-choose-2 pure-button">Add</button></a></div>
    </div>

    <br style="clear:both;">
    <?php $this->load->view("includes/left_menu") ?>
    <form name="myform" id="myform">
        <div class="right-contents">
            <table width="98%" cellpadding="5">
            <tr class="right-top">
                    <td width="8%">&nbsp;</td>
                    <td width="21%">Name</td>
                    <td width="18%">Image</td>
                    <td width="38%">Designation</td>
                    <td colspan="3" align="center">Actions</td>

                </tr>

                <?php if(is_array($items)): ?>

                <?php foreach($items as $row){?>
                <tr>

                    <td width="8%"><input type="checkbox" id="list"  name="del[]" value="<?php echo $row->team_id;?>" class="del"></td>

                    <td width="21%"><?php echo $row->name?></td>

                    <td width="18%"><img src="assets/icons/<?php echo $row->photo?>" width="100" height="70"></td>

                    <td width="38%"><?php echo $row->designation?></td>

                    <td width="5%"><a href="parexons_con/edit_team/<?php echo $row->team_id; ?>"><img src="assets/img/edit.png"></a></td>

                    <td width="5%"><img src="assets/img/27935.png"></td>

                    <td width="5%"><a href="parexons_con/delete/<?php echo 
$row->team_id;?>/<?php echo $page_url ?>/<?php echo 'team'; ?>/<?php echo 'team_id'; ?>"><img src="assets/img/Delete-icon.png"></a></td>
                </tr>

                <?php } endif; ?>
            </table>
        </div>
</form>

    <script>
        function checkAll(field)
        {
            for (i = 0; i < field.length; i++)
                field[i].checked = true ;
        }

        function uncheckAll(field)
        {
            for (i = 0; i < field.length; i++)
                field[i].checked = false ;
        }
    </script>
</div>

</div>
<script type="text/javascript">

    $(document).ready(function(){

        $("#delete").on('click', function(e) {
            var r =  confirm("are you sure you want to delete this");

            if (r==true) {
                e.preventDefault();

                var ids = $('.del:checked').map(function () {
                    return this.value;

                }).get();
                console.log(ids);

                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>parexons_con/delete_all",

                    data: 'id=' + ids,
                    type: "POST",


                    success: function (result) {


                        noty({text: 'thank you for providing information', type: 'success',settimeout:5000});


                        setTimeout(window.location.reload(), 1200000);

                    }
                });
            }
            });
    });



</script>

和控制器

function delete_all($del_id = NULL, $view = NULL, $table = NULL, $field_name = NULL)
{

$error = 'error';
$msg = 'deleted';

$ids = $this->input->post('id');
$explode = explode(",", $ids);
foreach ($explode as $id) {
    $query = $this->parexons_model->delete_row('team', array('team_id' => $id));

}

if ($query) {
    http_response_code(redirect("my_controller/team"), 5000);
} else {
    redirect("my_controller/team");
}
}

1 个答案:

答案 0 :(得分:0)

jquery ajax数据的语法错误

data: {id: ids},

其次不要重定向控制器功能,你需要将一些值传递给ajax成功,如

function delete_all($del_id = NULL, $view = NULL, $table = NULL, $field_name = NULL) {
$error = 'error';
$msg = 'deleted';
$ids = $this->input->post('id');
$explode = explode(",", $ids);
foreach ($explode as $id) {
    $query = $this->parexons_model->delete_row('team', array('team_id' => $id));

}
if ($query) {
   echo "success";
} else {
   echo "false";
}
}